Truly independent web browser
LibURL: Don't accept a plus sign in IPv4 numbers or URLPattern ports
Shannon Boothbd04b61c9fb6
diff --git a/Libraries/LibURL/Rust/src/pattern/pattern.rs b/Libraries/LibURL/Rust/src/pattern/pattern.rsindex cf6f29a4453..9889108c150 100644--- a/Libraries/LibURL/Rust/src/pattern/pattern.rs+++ b/Libraries/LibURL/Rust/src/pattern/pattern.rs@@ -215,7 +215,8 @@ impl Pattern {// 6. If processedInit["protocol"] is a special scheme and processedInit["port"] is a string which represents its// corresponding default port in radix-10 using ASCII digits then set processedInit["port"] to the empty string.if is_special_scheme(processed_init.protocol.as_ref().unwrap().as_bytes())- && let Ok(maybe_port) = processed_init.port.as_ref().unwrap().parse::<u16>()+ && let Some(maybe_port) =+ ak::parse_ascii_digits::<u16>(processed_init.port.as_ref().unwrap().as_bytes(), 10)&& Some(maybe_port) == default_port_for_scheme(processed_init.protocol.as_ref().unwrap()){processed_init.port = Some(String::new());diff --git a/Libraries/LibURL/Rust/src/url/host.rs b/Libraries/LibURL/Rust/src/url/host.rsindex 4a03e0103b1..50d660601d2 100644--- a/Libraries/LibURL/Rust/src/url/host.rs+++ b/Libraries/LibURL/Rust/src/url/host.rs@@ -249,7 +249,7 @@ fn parse_ipv4_number(mut input: &str) -> Option<ParsedIpv4Number> {// 7. If input contains a code point that is not a radix-R digit, then return failure.// 8. Let output be the mathematical integer value that is represented by input in radix-R notation, using ASCII hex// digits for digits with values 0 through 15.- let number = u32::from_str_radix(input, radix).ok()?;+ let number = ak::parse_ascii_digits::<u32>(input.as_bytes(), radix)?;// 9. Return (output, validationError).Some(ParsedIpv4Number {diff --git a/Tests/LibWeb/Text/expected/URL/invalid-urls.txt b/Tests/LibWeb/Text/expected/URL/invalid-urls.txtindex 4dce68a9aa7..3d5f29e3742 100644--- a/Tests/LibWeb/Text/expected/URL/invalid-urls.txt+++ b/Tests/LibWeb/Text/expected/URL/invalid-urls.txt@@ -1,3 +1,7 @@new URL('file://xn--/p', undefined)new URL('http://0xffffffff1', undefined)error creating URL: 'TypeError: Invalid URL'+new URL('http://+127.0.0.1/', undefined)+error creating URL: 'TypeError: Invalid URL'+new URL('http://0x+7f.1/', undefined)+error creating URL: 'TypeError: Invalid URL'diff --git a/Tests/LibWeb/Text/expected/URLPattern/default-port-with-plus-sign.txt b/Tests/LibWeb/Text/expected/URLPattern/default-port-with-plus-sign.txtnew file mode 100644index 00000000000..6002b71c56e--- /dev/null+++ b/Tests/LibWeb/Text/expected/URLPattern/default-port-with-plus-sign.txt@@ -0,0 +1 @@+TypeErrordiff --git a/Tests/LibWeb/Text/input/URL/invalid-urls.html b/Tests/LibWeb/Text/input/URL/invalid-urls.htmlindex 08d8dab85d0..350e3055f49 100644--- a/Tests/LibWeb/Text/input/URL/invalid-urls.html+++ b/Tests/LibWeb/Text/input/URL/invalid-urls.html@@ -5,6 +5,8 @@const urls = [{ input: 'file://xn--/p' },{ input: 'http://0xffffffff1' },+ { input: 'http://+127.0.0.1/' },+ { input: 'http://0x+7f.1/' },];for (url of urls) {diff --git a/Tests/LibWeb/Text/input/URLPattern/default-port-with-plus-sign.html b/Tests/LibWeb/Text/input/URLPattern/default-port-with-plus-sign.htmlnew file mode 100644index 00000000000..ae5d6ff23bc--- /dev/null+++ b/Tests/LibWeb/Text/input/URLPattern/default-port-with-plus-sign.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ test(() => {+ try {+ new URLPattern({ protocol: "http", port: "+80" });+ println("constructed");+ } catch (e) {+ println(e.name);+ }+ });+</script>