Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ fn url_parsing() {
assert_eq!(password, expected_password);
let host = host.serialize();
assert_eq!(host, expected_host)
assert_eq!(port, expected_port);
match port {
None => assert_eq!(None, expected_port),
Some(port) => assert_eq!(Some(port.to_string()), expected_port)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use assert_eq!(port.map(|x| x.to_string()), expected_port) here.

}
assert_eq!(Some(format!("/{}", path.connect("/"))), expected_path);
},
NonRelativeSchemeData(scheme_data) => {
Expand Down Expand Up @@ -105,7 +108,7 @@ struct Test {
username: String,
password: Option<String>,
host: String,
port: Option<u16>,
port: Option<String>,
path: Option<String>,
query: Option<String>,
fragment: Option<String>,
Expand Down
27 changes: 20 additions & 7 deletions src/urltestdata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ http://f:b/c
http://f:\s/c
http://f:\n/c s:http h:f p:/c
http://f:fifty-two/c
http://f:9999/c s:http h:f port:9999 p:/c
XFAIL http://f:999999/c s:http h:f port:999999 p:/c
http://f:\s21\s/\sb\s?\sd\s#\se\s
s:http h:example.org p:/foo/bar
\s\s\t s:http h:example.org p:/foo/bar
Expand Down Expand Up @@ -99,9 +99,17 @@ mailto:example.com/ s:mailto p:example.com/
data:text/html,test#test s:data p:text/html,test f:#test

# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/file.html

# Basic canonicalization, uppercase should be converted to lowercase
file:c:\\foo\\bar.html file:///tmp/mock/path s:file p:/c:/foo/bar.html

# Spaces should fail
\s\sFile:c|////foo\\bar.html s:file p:/c:////foo/bar.html

# This should fail
C|/foo/bar s:file p:/C:/foo/bar

# This should fail
/C|\\foo\\bar s:file p:/C:/foo/bar
//C|/foo/bar s:file p:/C:/foo/bar
//server/file s:file h:server p:/file
Expand Down Expand Up @@ -252,6 +260,7 @@ test.txt s:http h:www.example.com p:/test.txt
../../test.txt s:http h:www.example.com p:/test.txt
\u4E2D/test.txt s:http h:www.example.com p:/%E4%B8%AD/test.txt
http://www.example2.com s:http h:www.example2.com p:/
//www.example2.com s:http h:www.example2.com p:/

# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/host.html

Expand All @@ -264,21 +273,24 @@ http://example\sexample.com
# This should fail
http://Goo%20\sgoo%7C|.com

# This should fail
# U+3000 is mapped to U+0020 (space) which is disallowed
http://GOO\u00a0\u3000goo.com

# Other types of space (no-break, zero-width, zero-width-no-break) are
# name-prepped away to nothing.
# U+200B, U+2060, and U+FEFF, are ignored
XFAIL http://GOO\u200b\u2060\ufeffgoo.com s:http p:/ h:googoo.com

# Ideographic full stop (full-width period for Chinese, etc.) should be
# treated as a dot.
# U+3002 is mapped to U+002E (dot)
XFAIL http://www.foo\u3002bar.com s:http p:/ h:www.foo.bar.com

# Invalid unicode characters should fail...
# U+FDD0 is disallowed; %ef%b7%90 is U+FDD0
http://\ufdd0zyx.com

# ...This is the same as previous but with with escaped.
# ...This is the same as previous but escaped.
http://%ef%b7%90zyx.com

# Test name prepping, fullwidth input should be converted to ASCII and NOT
Expand Down Expand Up @@ -306,8 +318,10 @@ http://%25
http://hello%00

# Escaped numbers should be treated like IP addresses if they are.
# No special handling for IPv4 or IPv4-like URLs
XFAIL http://%30%78%63%30%2e%30%32%35%30.01 s:http p:/ h:127.0.0.1
XFAIL http://%30%78%63%30%2e%30%32%35%30.01%2e
http://%30%78%63%30%2e%30%32%35%30.01%2e s:http p:/ h:0xc0.0250.01.
http://192.168.0.257 s:http p:/ h:192.168.0.257

# Invalid escaping should trigger the regular host error handling.
http://%3g%78%63%30%2e%30%32%35%30%2E.01
Expand All @@ -318,8 +332,7 @@ http://192.168.0.1\shello

# Fullwidth and escaped UTF-8 fullwidth should still be treated as IP.
# These are "0Xc0.0250.01" in fullwidth.
XFAIL http://\uff10\uff38\uff43\uff10\uff0e\uff10\uff12\uff15\uff10\uff0e\uff10\uff11 s:http p:/ h:192.168.0.1
XFAIL http://\uff10\uff38\uff43\uff10\uff0e\uff10\uff12\uff15\uff10\uff0e\uff10\uff11 s:http p:/ h:0xc0.0250.01

# Broken IP addresses.
XFAIL http://192.168.0.257
# Broken IPv6
http://[google.com]