Skip to content

Commit 5eb5666

Browse files
Fix #121: Don't use regexp if there is no delimeter in the path in StringHelper::parsePath()
1 parent 4507541 commit 5eb5666

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

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

89
## 2.3.1 October 30, 2023
910

src/StringHelper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,14 @@ public static function parsePath(
509509
return [];
510510
}
511511

512+
if (!str_contains($path, $delimiter)) {
513+
if ($preserveDelimiterEscaping) {
514+
return [$path];
515+
}
516+
517+
return [str_replace($escapeCharacter . $escapeCharacter, $escapeCharacter, $path)];
518+
}
519+
512520
/** @psalm-var non-empty-list<array{0:string, 1:int}> $matches */
513521
$matches = preg_split(
514522
sprintf(

tests/StringHelperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ public function dataParsePath(): array
447447
['key1\.', '.', '\\', false, ['key1.']],
448448
['key1~.', '.', '~', false, ['key1.']],
449449
['key1~~', '.', '~', false, ['key1~']],
450+
['key1~~', '.', '~', true, ['key1~~']],
450451
['key1\\\\', '.', '\\', false, ['key1\\']],
451452
['key1~~.key2', '.', '~', false, ['key1~', 'key2']],
452453
['key1\\\\.key2', '.', '\\', false, ['key1\\', 'key2']],

0 commit comments

Comments
 (0)