Skip to content
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
4 changes: 2 additions & 2 deletions lib/TargetPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Expand Down
2 changes: 1 addition & 1 deletion smokeping_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/ValueObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

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)]);

Check warning on line 59 in tests/Unit/ValueObjectTest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Split this 138 characters long line (which is greater than 120 authorized).

See more on https://sonarcloud.io/project/issues?id=somethingwithproof_plugin_smokeping&issues=AaH3NNbfpTi907jw5NiM&open=AaH3NNbfpTi907jw5NiM&pullRequest=116

it('maps the master and slave locations to SmokePing file names', function () {
$path = TargetPath::fromString('Europe/gw1');
Expand All @@ -68,7 +68,7 @@
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 () {
Expand Down