From 7eccac9a0b763145ab1bb67a50576a34cc750567 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Sun, 29 Sep 2024 23:41:54 -0700 Subject: [PATCH] Add a test for and fix issue #974 (#975) * Add a test for issue 974 * Fix the issue * rename test --- url/src/parser.rs | 5 +++++ url/tests/expected_failures.txt | 1 - url/tests/unit.rs | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/url/src/parser.rs b/url/src/parser.rs index 8dd054df8..181a02e86 100644 --- a/url/src/parser.rs +++ b/url/src/parser.rs @@ -1120,6 +1120,11 @@ impl<'a> Parser<'a> { } input = remaining; } + + if !has_any_digit && context == Context::Setter && !input.is_empty() { + return Err(ParseError::InvalidPort); + } + let mut opt_port = Some(port as u16); if !has_any_digit || opt_port == default_port() { opt_port = None; diff --git a/url/tests/expected_failures.txt b/url/tests/expected_failures.txt index 91145db79..899e7f70f 100644 --- a/url/tests/expected_failures.txt +++ b/url/tests/expected_failures.txt @@ -39,7 +39,6 @@ set hostname to set hostname to <> set pathname to <> - set port to set href to set pathname to <\\\\> set pathname to diff --git a/url/tests/unit.rs b/url/tests/unit.rs index afe842beb..fd9a3ce70 100644 --- a/url/tests/unit.rs +++ b/url/tests/unit.rs @@ -1316,3 +1316,10 @@ fn issue_864() { url.set_path("x"); dbg!(&url); } + +#[test] +fn issue_974() { + let mut url = url::Url::parse("http://example.com:8000").unwrap(); + let _ = url::quirks::set_port(&mut url, "\u{0000}9000"); + assert_eq!(url.port(), Some(8000)); +}