diff --git a/lib/TargetPath.php b/lib/TargetPath.php index 7682403..39405d8 100644 --- a/lib/TargetPath.php +++ b/lib/TargetPath.php @@ -28,8 +28,8 @@ * name free of "..", slashes, and shell metacharacters. */ final readonly class TargetPath { - private const SEGMENT = '/^[-_0-9a-zA-Z]+$/'; - private const LOCATION = '/^[-_0-9a-zA-Z][-_.0-9a-zA-Z]*$/'; + private const SEGMENT = '/^[-_0-9a-zA-Z]+$/D'; + private const LOCATION = '/^[-_0-9a-zA-Z][-_.0-9a-zA-Z]*$/D'; private function __construct(public string $value) { } diff --git a/smokeping_import.php b/smokeping_import.php index 14eb769..69a4c92 100644 --- a/smokeping_import.php +++ b/smokeping_import.php @@ -75,7 +75,7 @@ if (is_array($smokeping_posted)) { foreach ($smokeping_posted as $smokeping_section) { - if (is_string($smokeping_section) && preg_match('/^[-_0-9a-zA-Z]+(\/[-_0-9a-zA-Z]+)*$/', $smokeping_section)) { + if (is_string($smokeping_section) && preg_match('/^[-_0-9a-zA-Z]+(\/[-_0-9a-zA-Z]+)*$/D', $smokeping_section)) { $smokeping_sections[] = $smokeping_section; } } diff --git a/tests/Unit/ValueObjectTest.php b/tests/Unit/ValueObjectTest.php index 067c8f9..8bbd628 100644 --- a/tests/Unit/ValueObjectTest.php +++ b/tests/Unit/ValueObjectTest.php @@ -56,7 +56,7 @@ function target_row(array $override = []): array { it('rejects paths that could escape the data directory or are not section names', function (string $path) { expect(fn () => TargetPath::fromString($path))->toThrow(InvalidArgumentException::class); - })->with(['', '/a', 'a/', 'a//b', '../a', 'a/../b', 'a.b', 'a b', 'a;b', str_repeat('a', 256)]); + })->with(['', '/a', 'a/', 'a//b', '../a', 'a/../b', 'a.b', 'a b', 'a;b', "gw1\n", "Europe/gw1\n", "Europe\n/gw1", str_repeat('a', 256)]); it('maps the master and slave locations to SmokePing file names', function () { $path = TargetPath::fromString('Europe/gw1'); @@ -68,7 +68,7 @@ function target_row(array $override = []): array { it('refuses location names that are not slave names', function (string $location) { expect(TargetPath::isLocation($location))->toBeFalse() ->and(fn () => TargetPath::fromString('a')->rrdFile('/m', $location))->toThrow(InvalidArgumentException::class); - })->with(['.', '..', '.hidden', 'a/b', 'a~b', 'a b']); + })->with(['.', '..', '.hidden', 'a/b', 'a~b', 'a b', "sydney\n"]); }); describe('TargetId', function () {