Skip to content

Commit 83bfa39

Browse files
committed
fix: Split multiple slashes tests into three
- `testPathWithMultipleSlashes()` modified to have a path with multiple slashes only in the middle of the path. - Renames `testProperlyTrimsLeadingSlashesToPreventXSS()` to `testGetPathNormalizesMultipleLeadingSlashesToSingleSlashToPreventXSS()`, and has it assert only against results of `getPath()`; on completion, it returns an associative array with the expected URI string and the URI instance. - Adds `testStringRepresentationWithMultipleSlashes()`; depends on `testGetPathNormalizesMultipleLeadingSlashesToSingleSlashToPreventXSS()`, and asserts that the string representation is identical to the original URI string. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
1 parent 8fb9b12 commit 83bfa39

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/UriIntegrationTest.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,38 @@ public function testPathWithMultipleSlashes()
233233
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
234234
}
235235

236-
$expected = 'http://example.org//valid///path';
236+
$expected = 'http://example.org/valid///path';
237237
$uri = $this->createUri($expected);
238238

239239
$this->assertInstanceOf(UriInterface::class, $uri);
240+
$this->assertSame('/valid///path', $uri->getPath());
240241
$this->assertSame($expected, (string) $uri);
242+
}
243+
244+
public function testGetPathNormalizesMultipleLeadingSlashesToSingleSlashToPreventXSS()
245+
{
246+
if (isset($this->skippedTests[__FUNCTION__])) {
247+
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
248+
}
249+
250+
$expected = 'http://example.org//valid///path';
251+
$uri = $this->createUri($expected);
252+
253+
$this->assertInstanceOf(UriInterface::class, $uri);
241254
$this->assertSame('/valid///path', $uri->getPath());
255+
256+
return [
257+
'expected' => $expected,
258+
'uri' => $uri,
259+
];
242260
}
243261

244-
public function testProperlyTrimsLeadingSlashesToPreventXSS()
262+
/**
263+
* @depends testGetPathNormalizesMultipleLeadingSlashesToSingleSlashToPreventXSS
264+
* @psalm-param array{expected: non-empty-string, uri: UriInterface} $test
265+
*/
266+
public function testStringRepresentationWithMultipleSlashes(array $test)
245267
{
246-
$url = 'http://example.org//zend.com';
247-
$uri = $this->createUri($url);
248-
$this->assertSame('http://example.org/zend.com', (string) $uri);
268+
$this->assertSame($test['expected'], (string) $test['uri']);
249269
}
250270
}

0 commit comments

Comments
 (0)