Skip to content

Commit bb2fc7d

Browse files
committed
Check empty sanitization string run-time
Annotating with PHPStan is fine, but requires some work to be done by the caller to not pass empty strings. This is more friendly. Partially reverts some work done in #28
1 parent 33e06da commit bb2fc7d

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/PhpInfo.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ public function doNotSanitizeSessionId(): self
6666
}
6767

6868

69-
/**
70-
* @param non-empty-string $sanitize
71-
*/
7269
public function addSanitization(string $sanitize, ?string $with = null): self
7370
{
7471
$this->sanitizer->addSanitization($sanitize, $with);

src/SensitiveValueSanitizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ public function doNotSanitizeSessionId(): self
6464
}
6565

6666

67-
/**
68-
* @param non-empty-string $sanitize
69-
*/
7067
public function addSanitization(string $sanitize, ?string $with = null): self
7168
{
69+
if ($sanitize === '') {
70+
return $this;
71+
}
7272
$this->sanitize[$sanitize] = $this->sanitize[urlencode($sanitize)] = $with ?? $this->sanitizeWith;
7373
return $this;
7474
}

tests/SensitiveValueSanitizerTest.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ class SensitiveValueSanitizerTest extends TestCase
143143
Assert::notContains($sessionId, $html);
144144
}
145145

146+
147+
public function testAddSanitizationEmptyString(): void
148+
{
149+
Assert::noError(function () use (&$string): void {
150+
$string = (new SensitiveValueSanitizer())->addSanitization('', '💫')->sanitize('foo');
151+
});
152+
Assert::same('foo', $string);
153+
Assert::notContains('💫', $string);
154+
}
155+
146156
}
147157

148158
(new SensitiveValueSanitizerTest())->run();

0 commit comments

Comments
 (0)