Skip to content

Commit

Permalink
Fix #121: Don't use regexp if there is no delimeter in the path in `S…
Browse files Browse the repository at this point in the history
…tringHelper::parsePath()`
  • Loading branch information
viktorprogger committed Dec 18, 2023
1 parent 4507541 commit 5eb5666
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- New #118: Add `findBetween()`, `findBetweenFirst()` and `findBetweenLast()` methods to `StringHelper` to retrieve
a substring that lies between two strings (@salehhashemi1992)
- Enh #121: Don't use regexp if there is no delimeter in the path in `StringHelper::parsePath()` (@viktorprogger)

## 2.3.1 October 30, 2023

Expand Down
8 changes: 8 additions & 0 deletions src/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,14 @@ public static function parsePath(
return [];
}

if (!str_contains($path, $delimiter)) {
if ($preserveDelimiterEscaping) {
return [$path];
}

return [str_replace($escapeCharacter . $escapeCharacter, $escapeCharacter, $path)];
}

/** @psalm-var non-empty-list<array{0:string, 1:int}> $matches */
$matches = preg_split(
sprintf(
Expand Down
1 change: 1 addition & 0 deletions tests/StringHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ public function dataParsePath(): array
['key1\.', '.', '\\', false, ['key1.']],
['key1~.', '.', '~', false, ['key1.']],
['key1~~', '.', '~', false, ['key1~']],
['key1~~', '.', '~', true, ['key1~~']],
['key1\\\\', '.', '\\', false, ['key1\\']],
['key1~~.key2', '.', '~', false, ['key1~', 'key2']],
['key1\\\\.key2', '.', '\\', false, ['key1\\', 'key2']],
Expand Down

0 comments on commit 5eb5666

Please sign in to comment.