Skip to content

Commit

Permalink
Merge pull request #16 from tonysm/fix/tm-escape-str-for-regex
Browse files Browse the repository at this point in the history
Wrap regex contact with preg_quote
  • Loading branch information
tonysm authored Jun 30, 2022
2 parents 2424b7e + 3fcec8f commit 5597237
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Commands/PinCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function pattern(string $package): string
{
return sprintf(
'#^Importmap::pin\("%s".*$#',
$package,
preg_quote($package),
);
}
}
4 changes: 2 additions & 2 deletions src/Packager.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function vendoredPinFor(string $package, string $url): string
public function packaged(string $package): bool
{
return (bool) preg_match(
sprintf('#Importmap::pin\("%s"#', str_replace('#', '\#', $package)),
sprintf('#Importmap::pin\("%s"#', preg_quote($package)),
File::get(base_path($this->importmapPath)),
);
}
Expand All @@ -86,7 +86,7 @@ private function removePackageFromImportmap(string $package)
{
$contents = collect(File::lines(base_path($this->importmapPath)))
->reject(fn (string $line) => (
preg_match(sprintf('#Importmap::pin\("%s"#', $package), $line)
preg_match(sprintf('#Importmap::pin\("%s"#', preg_quote($package)), $line)
))
->join(PHP_EOL);

Expand Down

0 comments on commit 5597237

Please sign in to comment.