Skip to content

Commit f207dc5

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: reject URLs containing whitespaces Update validators.fa.xlf [HttpClient] Fix a typo in NoPrivateNetworkHttpClient
2 parents a25620f + 7f16925 commit f207dc5

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

Diff for: Tests/TextSanitizer/UrlSanitizerTest.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,10 @@ public static function provideParse(): iterable
358358
'non-special://:@untrusted.com/x' => ['scheme' => 'non-special', 'host' => 'untrusted.com'],
359359
'http:foo.com' => ['scheme' => 'http', 'host' => null],
360360
" :foo.com \n" => null,
361-
' foo.com ' => ['scheme' => null, 'host' => null],
361+
' foo.com ' => null,
362362
'a: foo.com' => null,
363-
'http://f:21/ b ? d # e ' => ['scheme' => 'http', 'host' => 'f'],
364-
'lolscheme:x x#x x' => ['scheme' => 'lolscheme', 'host' => null],
363+
'http://f:21/ b ? d # e ' => null,
364+
'lolscheme:x x#x x' => null,
365365
'http://f:/c' => ['scheme' => 'http', 'host' => 'f'],
366366
'http://f:0/c' => ['scheme' => 'http', 'host' => 'f'],
367367
'http://f:00000000000000/c' => ['scheme' => 'http', 'host' => 'f'],
@@ -434,7 +434,7 @@ public static function provideParse(): iterable
434434
'javascript:example.com/' => ['scheme' => 'javascript', 'host' => null],
435435
'mailto:example.com/' => ['scheme' => 'mailto', 'host' => null],
436436
'/a/b/c' => ['scheme' => null, 'host' => null],
437-
'/a/ /c' => ['scheme' => null, 'host' => null],
437+
'/a/ /c' => null,
438438
'/a%2fc' => ['scheme' => null, 'host' => null],
439439
'/a/%2f/c' => ['scheme' => null, 'host' => null],
440440
'' => ['scheme' => null, 'host' => null],
@@ -495,10 +495,10 @@ public static function provideParse(): iterable
495495
'http://example.com/你好你好' => ['scheme' => 'http', 'host' => 'example.com'],
496496
'http://example.com/‥/foo' => ['scheme' => 'http', 'host' => 'example.com'],
497497
"http://example.com/\u{feff}/foo" => ['scheme' => 'http', 'host' => 'example.com'],
498-
"http://example.com\u{002f}\u{202e}\u{002f}\u{0066}\u{006f}\u{006f}\u{002f}\u{202d}\u{002f}\u{0062}\u{0061}\u{0072}\u{0027}\u{0020}" => ['scheme' => 'http', 'host' => 'example.com'],
498+
"http://example.com\u{002f}\u{202e}\u{002f}\u{0066}\u{006f}\u{006f}\u{002f}\u{202d}\u{002f}\u{0062}\u{0061}\u{0072}\u{0027}\u{0020}" => null,
499499
'http://www.google.com/foo?bar=baz#' => ['scheme' => 'http', 'host' => 'www.google.com'],
500-
'http://www.google.com/foo?bar=baz# »' => ['scheme' => 'http', 'host' => 'www.google.com'],
501-
'data:test# »' => ['scheme' => 'data', 'host' => null],
500+
'http://www.google.com/foo?bar=baz# »' => null,
501+
'data:test# »' => null,
502502
'http://www.google.com' => ['scheme' => 'http', 'host' => 'www.google.com'],
503503
'http://192.0x00A80001' => ['scheme' => 'http', 'host' => '192.0x00A80001'],
504504
'http://www/foo%2Ehtml' => ['scheme' => 'http', 'host' => 'www'],
@@ -706,11 +706,11 @@ public static function provideParse(): iterable
706706
'test-a-colon-slash-slash-b.html' => ['scheme' => null, 'host' => null],
707707
'http://example.org/test?a#bc' => ['scheme' => 'http', 'host' => 'example.org'],
708708
'http:\\/\\/f:b\\/c' => ['scheme' => 'http', 'host' => null],
709-
'http:\\/\\/f: \\/c' => ['scheme' => 'http', 'host' => null],
709+
'http:\\/\\/f: \\/c' => null,
710710
'http:\\/\\/f:fifty-two\\/c' => ['scheme' => 'http', 'host' => null],
711711
'http:\\/\\/f:999999\\/c' => ['scheme' => 'http', 'host' => null],
712712
'non-special:\\/\\/f:999999\\/c' => ['scheme' => 'non-special', 'host' => null],
713-
'http:\\/\\/f: 21 \\/ b ? d # e ' => ['scheme' => 'http', 'host' => null],
713+
'http:\\/\\/f: 21 \\/ b ? d # e ' => null,
714714
'http:\\/\\/[1::2]:3:4' => ['scheme' => 'http', 'host' => null],
715715
'http:\\/\\/2001::1' => ['scheme' => 'http', 'host' => null],
716716
'http:\\/\\/2001::1]' => ['scheme' => 'http', 'host' => null],
@@ -734,8 +734,8 @@ public static function provideParse(): iterable
734734
'http:@:www.example.com' => ['scheme' => 'http', 'host' => null],
735735
'http:\\/@:www.example.com' => ['scheme' => 'http', 'host' => null],
736736
'http:\\/\\/@:www.example.com' => ['scheme' => 'http', 'host' => null],
737-
'http:\\/\\/example example.com' => ['scheme' => 'http', 'host' => null],
738-
'http:\\/\\/Goo%20 goo%7C|.com' => ['scheme' => 'http', 'host' => null],
737+
'http:\\/\\/example example.com' => null,
738+
'http:\\/\\/Goo%20 goo%7C|.com' => null,
739739
'http:\\/\\/[]' => ['scheme' => 'http', 'host' => null],
740740
'http:\\/\\/[:]' => ['scheme' => 'http', 'host' => null],
741741
'http:\\/\\/GOO\\u00a0\\u3000goo.com' => ['scheme' => 'http', 'host' => null],
@@ -752,8 +752,8 @@ public static function provideParse(): iterable
752752
'http:\\/\\/hello%00' => ['scheme' => 'http', 'host' => null],
753753
'http:\\/\\/192.168.0.257' => ['scheme' => 'http', 'host' => null],
754754
'http:\\/\\/%3g%78%63%30%2e%30%32%35%30%2E.01' => ['scheme' => 'http', 'host' => null],
755-
'http:\\/\\/192.168.0.1 hello' => ['scheme' => 'http', 'host' => null],
756-
'https:\\/\\/x x:12' => ['scheme' => 'https', 'host' => null],
755+
'http:\\/\\/192.168.0.1 hello' => null,
756+
'https:\\/\\/x x:12' => null,
757757
'http:\\/\\/[www.google.com]\\/' => ['scheme' => 'http', 'host' => null],
758758
'http:\\/\\/[google.com]' => ['scheme' => 'http', 'host' => null],
759759
'http:\\/\\/[::1.2.3.4x]' => ['scheme' => 'http', 'host' => null],
@@ -763,7 +763,7 @@ public static function provideParse(): iterable
763763
'..\\/i' => ['scheme' => null, 'host' => null],
764764
'\\/i' => ['scheme' => null, 'host' => null],
765765
'sc:\\/\\/\\u0000\\/' => ['scheme' => 'sc', 'host' => null],
766-
'sc:\\/\\/ \\/' => ['scheme' => 'sc', 'host' => null],
766+
'sc:\\/\\/ \\/' => null,
767767
'sc:\\/\\/@\\/' => ['scheme' => 'sc', 'host' => null],
768768
'sc:\\/\\/te@s:t@\\/' => ['scheme' => 'sc', 'host' => null],
769769
'sc:\\/\\/:\\/' => ['scheme' => 'sc', 'host' => null],

Diff for: TextSanitizer/UrlSanitizer.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@ public static function parse(string $url): ?array
9494
}
9595

9696
try {
97-
return UriString::parse($url);
97+
$parsedUrl = UriString::parse($url);
98+
99+
if (preg_match('/\s/', $url)) {
100+
return null;
101+
}
102+
103+
return $parsedUrl;
98104
} catch (SyntaxError) {
99105
return null;
100106
}

0 commit comments

Comments
 (0)