Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve path parsing #121

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -49,9 +49,9 @@
*
* @return int The number of bytes in the given string.
*/
public static function byteLength(string|null $input): int

Check warning on line 52 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "PublicVisibility": --- Original +++ New @@ @@ * * @return int The number of bytes in the given string. */ - public static function byteLength(string|null $input) : int + protected static function byteLength(string|null $input) : int { return mb_strlen((string) $input, '8bit'); }
{
return mb_strlen((string)$input, '8bit');

Check warning on line 54 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "MBString": --- Original +++ New @@ @@ */ public static function byteLength(string|null $input) : int { - return mb_strlen((string) $input, '8bit'); + return strlen((string) $input); } /** * Returns the portion of string specified by the start and length parameters.
}

/**
Expand Down Expand Up @@ -509,6 +509,14 @@
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
Loading