Lines Matching full:url
1 // Copyright 2013-2014 The rust-url developers.
15 use url::{form_urlencoded, Host, Origin, Url};
20 assert_eq!(size_of::<Url>(), size_of::<Option<Url>>()); in size()
25 let base: Url = "sc://%C3%B1".parse().unwrap(); in test_relative()
26 let url = base.join("/resources/testharness.js").unwrap(); in test_relative() localVariable
27 assert_eq!(url.as_str(), "sc://%C3%B1/resources/testharness.js"); in test_relative()
32 let base: Url = "sc://%C3%B1".parse().unwrap(); in test_relative_empty()
33 let url = base.join("").unwrap(); in test_relative_empty() localVariable
34 assert_eq!(url.as_str(), "sc://%C3%B1"); in test_relative_empty()
39 let mut base: Url = "moz://foo:bar@servo/baz".parse().unwrap(); in test_set_empty_host()
50 use url::quirks; in test_set_empty_hostname()
51 let mut base: Url = "moz://foo@servo/baz".parse().unwrap(); in test_set_empty_hostname()
54 "setting an empty hostname to a url with a username should fail" in test_set_empty_hostname()
59 "setting an empty hostname to a url with a password should fail" in test_set_empty_hostname()
71 let url = Url::from_file_path(Path::new($path)).unwrap(); localVariable
72 assert_eq!(url.host(), None);
73 assert_eq!(url.path(), $url_path);
74 assert_eq!(url.to_file_path(), Ok(PathBuf::from($path)));
81 assert_eq!(Url::from_file_path(Path::new("relative")), Err(())); in new_file_paths()
82 assert_eq!(Url::from_file_path(Path::new("../relative")), Err(())); in new_file_paths()
85 assert_eq!(Url::from_file_path(Path::new("relative")), Err(())); in new_file_paths()
86 assert_eq!(Url::from_file_path(Path::new(r"..\relative")), Err(())); in new_file_paths()
87 assert_eq!(Url::from_file_path(Path::new(r"\drive-relative")), Err(())); in new_file_paths()
88 assert_eq!(Url::from_file_path(Path::new(r"\\ucn\")), Err(())); in new_file_paths()
104 let url = Url::from_file_path(Path::new(OsStr::from_bytes(b"/foo/ba\x80r"))).unwrap(); in new_path_bad_utf8() localVariable
106 assert_eq!(url.to_file_path(), Ok(PathBuf::from(os_str))); in new_path_bad_utf8()
116 assert!(Url::parse("file:///C:/foo/ba%80r") in new_path_windows_fun()
123 assert!(Url::from_file_path(path).is_ok()); in new_path_windows_fun()
126 let url = Url::parse("file:///C%3A/foo/bar").unwrap(); in new_path_windows_fun() localVariable
127 assert_eq!(url.to_file_path(), Ok(PathBuf::from(r"C:\foo\bar"))); in new_path_windows_fun()
134 assert_eq!(Url::from_directory_path(Path::new("relative")), Err(())); in new_directory_paths()
135 assert_eq!(Url::from_directory_path(Path::new("../relative")), Err(())); in new_directory_paths()
137 let url = Url::from_directory_path(Path::new("/foo/bar")).unwrap(); in new_directory_paths() localVariable
138 assert_eq!(url.host(), None); in new_directory_paths()
139 assert_eq!(url.path(), "/foo/bar/"); in new_directory_paths()
142 assert_eq!(Url::from_directory_path(Path::new("relative")), Err(())); in new_directory_paths()
143 assert_eq!(Url::from_directory_path(Path::new(r"..\relative")), Err(())); in new_directory_paths()
145 Url::from_directory_path(Path::new(r"\drive-relative")), in new_directory_paths()
148 assert_eq!(Url::from_directory_path(Path::new(r"\\ucn\")), Err(())); in new_directory_paths()
150 let url = Url::from_directory_path(Path::new(r"C:\foo\bar")).unwrap(); in new_directory_paths() localVariable
151 assert_eq!(url.host(), None); in new_directory_paths()
152 assert_eq!(url.path(), "/C:/foo/bar/"); in new_directory_paths()
158 let mut special_url = "http://foobar.com".parse::<Url>().unwrap(); in path_backslash_fun()
162 let mut nonspecial_url = "thing://foobar.com".parse::<Url>().unwrap(); in path_backslash_fun()
169 assert!("http://testing.com/this".parse::<Url>().is_ok()); in from_str()
174 let url = Url::parse_with_params( in parse_with_params() localVariable
181 url.as_str(), in parse_with_params()
188 let url: Url = "file:a".parse().unwrap(); in issue_124() localVariable
189 assert_eq!(url.path(), "/a"); in issue_124()
190 let url: Url = "file:...".parse().unwrap(); in issue_124() localVariable
191 assert_eq!(url.path(), "/..."); in issue_124()
192 let url: Url = "file:..".parse().unwrap(); in issue_124() localVariable
193 assert_eq!(url.path(), "/"); in issue_124()
201 fn check_eq(a: &Url, b: &Url) { in test_equality() argument
211 fn url(s: &str) -> Url { in test_equality() function
218 let a: Url = url("https://example.com/"); in test_equality()
219 let b: Url = url("https://example.com:443/"); in test_equality()
223 let a: Url = url("http://example.com/"); in test_equality()
224 let b: Url = url("http://example.com:8080/"); in test_equality()
228 let a: Url = url("http://example.com/"); in test_equality()
229 let b: Url = url("https://example.com/"); in test_equality()
233 let a: Url = url("http://foo.com/"); in test_equality()
234 let b: Url = url("http://bar.com/"); in test_equality()
238 let a: Url = url("http://foo.com"); in test_equality()
239 let b: Url = url("http://foo.com/"); in test_equality()
246 assert_eq!(Url::parse(input).unwrap().host(), Some(host)); in host()
275 assert!(Url::parse("http://42.0x1232131").is_err()); in host()
276 assert!(Url::parse("http://192.168.0.257").is_err()); in host()
286 // but https://url.spec.whatwg.org/#concept-ipv6-serializer specifies not to. in host_serialization()
290 Url::parse("http://[0::2]").unwrap().host_str(), in host_serialization()
294 Url::parse("http://[0::ffff:0:2]").unwrap().host_str(), in host_serialization()
301 assert!("http://goșu.ro".parse::<Url>().is_ok()); in test_idna()
303 Url::parse("http://☃.net/").unwrap().host(), in test_idna()
307 .parse::<Url>() in test_idna()
333 let url = Url::parse(input).unwrap(); in test_serialization() localVariable
334 assert_eq!(url.as_str(), result); in test_serialization()
377 /// https://github.com/servo/rust-url/issues/61
379 let mut url = Url::parse("http://mozilla.org").unwrap(); in issue_61() localVariable
380 url.set_scheme("https").unwrap(); in issue_61()
381 assert_eq!(url.port(), None); in issue_61()
382 assert_eq!(url.port_or_known_default(), Some(443)); in issue_61()
383 url.check_invariants().unwrap(); in issue_61()
388 /// https://github.com/servo/rust-url/issues/197
390 let mut url = Url::from_file_path("/").expect("Failed to parse path"); in issue_197() localVariable
391 url.check_invariants().unwrap(); in issue_197()
393 url, in issue_197()
394 Url::parse("file:///").expect("Failed to parse path + protocol") in issue_197()
396 url.path_segments_mut() in issue_197()
403 Url::parse("mailto:").unwrap().cannot_be_a_base(); in issue_241()
407 /// https://github.com/servo/rust-url/issues/222
409 let mut url: Url = "http://localhost:6767/foo/bar?a=b".parse().unwrap(); in append_trailing_slash() localVariable
410 url.check_invariants().unwrap(); in append_trailing_slash()
411 url.path_segments_mut().unwrap().push(""); in append_trailing_slash()
412 url.check_invariants().unwrap(); in append_trailing_slash()
413 assert_eq!(url.to_string(), "http://localhost:6767/foo/bar/?a=b"); in append_trailing_slash()
417 /// https://github.com/servo/rust-url/issues/227
419 let mut url: Url = "http://localhost:6767/foo/bar".parse().unwrap(); in extend_query_pairs_then_mutate() localVariable
420 url.query_pairs_mut() in extend_query_pairs_then_mutate()
422 url.check_invariants().unwrap(); in extend_query_pairs_then_mutate()
424 url.to_string(), in extend_query_pairs_then_mutate()
427 url.path_segments_mut().unwrap().push("some_other_path"); in extend_query_pairs_then_mutate()
428 url.check_invariants().unwrap(); in extend_query_pairs_then_mutate()
430 url.to_string(), in extend_query_pairs_then_mutate()
436 /// https://github.com/servo/rust-url/issues/222
438 let mut url: Url = "http://localhost:6767/foo/bar?a=b".parse().unwrap(); in append_empty_segment_then_mutate() localVariable
439 url.check_invariants().unwrap(); in append_empty_segment_then_mutate()
440 url.path_segments_mut().unwrap().push("").pop(); in append_empty_segment_then_mutate()
441 url.check_invariants().unwrap(); in append_empty_segment_then_mutate()
442 assert_eq!(url.to_string(), "http://localhost:6767/foo/bar?a=b"); in append_empty_segment_then_mutate()
446 /// https://github.com/servo/rust-url/issues/243
448 let mut url = Url::parse("https://example.net/hello").unwrap(); in test_set_host() localVariable
449 url.set_host(Some("foo.com")).unwrap(); in test_set_host()
450 assert_eq!(url.as_str(), "https://foo.com/hello"); in test_set_host()
451 assert!(url.set_host(None).is_err()); in test_set_host()
452 assert_eq!(url.as_str(), "https://foo.com/hello"); in test_set_host()
453 assert!(url.set_host(Some("")).is_err()); in test_set_host()
454 assert_eq!(url.as_str(), "https://foo.com/hello"); in test_set_host()
456 let mut url = Url::parse("foobar://example.net/hello").unwrap(); in test_set_host() localVariable
457 url.set_host(None).unwrap(); in test_set_host()
458 assert_eq!(url.as_str(), "foobar:/hello"); in test_set_host()
460 let mut url = Url::parse("foo://ș").unwrap(); in test_set_host() localVariable
461 assert_eq!(url.as_str(), "foo://%C8%99"); in test_set_host()
462 url.set_host(Some("goșu.ro")).unwrap(); in test_set_host()
463 assert_eq!(url.as_str(), "foo://go%C8%99u.ro"); in test_set_host()
467 // https://github.com/servo/rust-url/issues/166
473 assert_eq!(Url::parse("file://./foo").unwrap().domain(), Some(".")); in test_leading_dots()
477 /// https://github.com/servo/rust-url/issues/302
488 let origin = &Url::parse("http://example.net/").unwrap().origin(); in test_origin_hash()
491 Url::parse("http://example.net:80/").unwrap().origin(), in test_origin_hash()
492 Url::parse("http://example.net:81/").unwrap().origin(), in test_origin_hash()
493 Url::parse("http://example.net").unwrap().origin(), in test_origin_hash()
494 Url::parse("http://example.net/hello").unwrap().origin(), in test_origin_hash()
495 Url::parse("https://example.net").unwrap().origin(), in test_origin_hash()
496 Url::parse("ftp://example.net").unwrap().origin(), in test_origin_hash()
497 Url::parse("file://example.net").unwrap().origin(), in test_origin_hash()
498 Url::parse("http://user@example.net/").unwrap().origin(), in test_origin_hash()
499 Url::parse("http://user:pass@example.net/") in test_origin_hash()
512 let opaque_origin = Url::parse("file://example.net").unwrap().origin(); in test_origin_hash()
513 let same_opaque_origin = Url::parse("file://example.net").unwrap().origin(); in test_origin_hash()
514 let other_opaque_origin = Url::parse("file://other").unwrap().origin(); in test_origin_hash()
522 let origin = &Url::parse("http://example.net/").unwrap().origin(); in test_origin_blob_equality()
523 let blob_origin = &Url::parse("blob:http://example.net/").unwrap().origin(); in test_origin_blob_equality()
531 assert!(!&Url::parse("blob:malformed//").unwrap().origin().is_tuple()) in test_origin_opaque()
543 let origin = Url::parse(unicode_url).unwrap().origin(); in test_origin_unicode_serialization()
548 Url::parse("http://example.net/").unwrap().origin(), in test_origin_unicode_serialization()
549 Url::parse("http://example.net:80/").unwrap().origin(), in test_origin_unicode_serialization()
550 Url::parse("http://example.net:81/").unwrap().origin(), in test_origin_unicode_serialization()
551 Url::parse("http://example.net").unwrap().origin(), in test_origin_unicode_serialization()
552 Url::parse("http://example.net/hello").unwrap().origin(), in test_origin_unicode_serialization()
553 Url::parse("https://example.net").unwrap().origin(), in test_origin_unicode_serialization()
554 Url::parse("ftp://example.net").unwrap().origin(), in test_origin_unicode_serialization()
555 Url::parse("file://example.net").unwrap().origin(), in test_origin_unicode_serialization()
556 Url::parse("http://user@example.net/").unwrap().origin(), in test_origin_unicode_serialization()
557 Url::parse("http://user:pass@example.net/") in test_origin_unicode_serialization()
560 Url::parse("http://127.0.0.1").unwrap().origin(), in test_origin_unicode_serialization()
590 let url = url::Url::parse(url_string).unwrap(); in test_socket_addrs() localVariable
591 let addrs = url in test_socket_addrs()
592 .socket_addrs(|| match url.scheme() { in test_socket_addrs()
606 let mut no_base_url = Url::parse("mailto:test@example.net").unwrap(); in test_no_base_url()
622 let url = Url::parse("https://127.0.0.1/").unwrap(); in test_domain() localVariable
623 assert_eq!(url.domain(), None); in test_domain()
625 let url = Url::parse("mailto:test@example.net").unwrap(); in test_domain() localVariable
626 assert_eq!(url.domain(), None); in test_domain()
628 let url = Url::parse("https://example.com/").unwrap(); in test_domain() localVariable
629 assert_eq!(url.domain(), Some("example.com")); in test_domain()
634 let url = Url::parse("https://example.com/products?page=2#fragment").unwrap(); in test_query() localVariable
635 assert_eq!(url.query(), Some("page=2")); in test_query()
637 url.query_pairs().next(), in test_query()
641 let url = Url::parse("https://example.com/products").unwrap(); in test_query() localVariable
642 assert!(url.query().is_none()); in test_query()
643 assert_eq!(url.query_pairs().count(), 0); in test_query()
645 let url = Url::parse("https://example.com/?country=español").unwrap(); in test_query() localVariable
646 assert_eq!(url.query(), Some("country=espa%C3%B1ol")); in test_query()
648 url.query_pairs().next(), in test_query()
652 let url = Url::parse("https://example.com/products?page=2&sort=desc").unwrap(); in test_query() localVariable
653 assert_eq!(url.query(), Some("page=2&sort=desc")); in test_query()
654 let mut pairs = url.query_pairs(); in test_query()
668 let url = Url::parse("https://example.com/#fragment").unwrap(); in test_fragment() localVariable
669 assert_eq!(url.fragment(), Some("fragment")); in test_fragment()
671 let url = Url::parse("https://example.com/").unwrap(); in test_fragment() localVariable
672 assert_eq!(url.fragment(), None); in test_fragment()
677 let mut url = Url::parse("http://example.com").unwrap(); in test_set_ip_host() localVariable
679 url.set_ip_host("127.0.0.1".parse().unwrap()).unwrap(); in test_set_ip_host()
680 assert_eq!(url.host_str(), Some("127.0.0.1")); in test_set_ip_host()
682 url.set_ip_host("::1".parse().unwrap()).unwrap(); in test_set_ip_host()
683 assert_eq!(url.host_str(), Some("[::1]")); in test_set_ip_host()
688 use url::quirks::set_href; in test_set_href()
690 let mut url = Url::parse("https://existing.url").unwrap(); in test_set_href() localVariable
692 assert!(set_href(&mut url, "mal//formed").is_err()); in test_set_href()
695 &mut url, in test_set_href()
700 url, in test_set_href()
701 Url::parse("https://user:pass@domain.com:9742/path/file.ext?key=val&key2=val2#fragment") in test_set_href()
708 use url::quirks::{domain_to_ascii, domain_to_unicode}; in test_domain_encoding_quirks()
717 for url in &data { in test_domain_encoding_quirks()
718 assert_eq!(domain_to_ascii(url.0), url.1); in test_domain_encoding_quirks()
719 assert_eq!(domain_to_unicode(url.0), url.2); in test_domain_encoding_quirks()
729 let url = Url::from_file_path(Path::new(r"\\host\share\path\file.txt")).unwrap(); in test_windows_unc_path() localVariable
730 assert_eq!(url.as_str(), "file://host/share/path/file.txt"); in test_windows_unc_path()
732 let url = Url::from_file_path(Path::new(r"\\höst\share\path\file.txt")).unwrap(); in test_windows_unc_path() localVariable
733 assert_eq!(url.as_str(), "file://xn--hst-sna/share/path/file.txt"); in test_windows_unc_path()
735 let url = Url::from_file_path(Path::new(r"\\192.168.0.1\share\path\file.txt")).unwrap(); in test_windows_unc_path() localVariable
736 assert_eq!(url.host(), Some(Host::Ipv4(Ipv4Addr::new(192, 168, 0, 1)))); in test_windows_unc_path()
738 let path = url.to_file_path().unwrap(); in test_windows_unc_path()
742 let url = Url::from_file_path(Path::new(r"\\?\UNC\host\share\path\file.txt")).unwrap(); in test_windows_unc_path() localVariable
743 assert_eq!(url.as_str(), "file://host/share/path/file.txt"); in test_windows_unc_path()
746 let url = Url::from_file_path(Path::new(r"\\.\some\path\file.txt")); in test_windows_unc_path() localVariable
747 assert!(url.is_err()); in test_windows_unc_path()
752 use url::SyntaxViolation::*; in test_syntax_violation_callback()
754 let url = Url::options() in test_syntax_violation_callback() localVariable
758 assert_eq!(url.port(), Some(42)); in test_syntax_violation_callback()
768 use url::SyntaxViolation::*; in test_syntax_violation_callback_lifetimes()
772 let url = Url::options() in test_syntax_violation_callback_lifetimes() localVariable
776 assert_eq!(url.port(), Some(42)); in test_syntax_violation_callback_lifetimes()
779 let url = Url::options() in test_syntax_violation_callback_lifetimes() localVariable
783 assert_eq!(url.path(), "/path"); in test_syntax_violation_callback_lifetimes()
789 use url::SyntaxViolation::*; in test_syntax_violation_callback_types()
794 …ntials, "embedding authentication information (username or password) in an URL is not recommended"… in test_syntax_violation_callback_types()
798 ("http://mozilla.org/^", NonUrlCodePoint, "non-URL code point"), in test_syntax_violation_callback_types()
799 …("http://mozilla.org/#\00", NullInFragment, "NULL characters are ignored in URL fragment identifie… in test_syntax_violation_callback_types()
807 Url::options() in test_syntax_violation_callback_types()
821 use url::SyntaxViolation::*; in test_options_reuse()
825 let options = Url::options().syntax_violation_callback(Some(&vfn)); in test_options_reuse()
826 let url = options.parse("http:////mozilla.org").unwrap(); in test_options_reuse() localVariable
828 let options = options.base_url(Some(&url)); in test_options_reuse()
829 let url = options.parse("/sub\\path").unwrap(); in test_options_reuse() localVariable
830 assert_eq!(url.as_str(), "http://mozilla.org/sub/path"); in test_options_reuse()
834 /// https://github.com/servo/rust-url/issues/505
839 use url::Url; in test_url_from_file_path()
842 let u = Url::from_file_path(p).unwrap(); in test_url_from_file_path()
847 /// https://github.com/servo/rust-url/issues/505
852 use url::Url;
855 let u = Url::from_file_path(p).unwrap();
862 let mut db_url = url::Url::parse("postgres://postgres@localhost/").unwrap();
871 let mut db_url = url::Url::parse("postgres://postgres@localhost/").unwrap();
886 let mut db_url = url::Url::parse("postgres://postgres@localhost/").unwrap();
898 let mut url: Url = "http://localhost:6767/foo/bar".parse().unwrap(); localVariable
899 let result = url.set_scheme("file");
900 assert_eq!(url.to_string(), "http://localhost:6767/foo/bar");
906 let mut url = Url::parse("arhttpsps:/.//eom/dae.com/\\\\t\\:").unwrap(); localVariable
907 url::quirks::set_hostname(&mut url, "//eom/datcom/\\\\t\\://eom/data.cs").unwrap();
912 let mut url = Url::parse("m://").unwrap(); localVariable
913 let mut segments = url.path_segments_mut().unwrap();
920 use url::Position::*;
973 let url = Url::parse(expected_slices.full).unwrap(); localVariable
974 assert_eq!(&url[..], expected_slices.full);
975 assert_eq!(&url[BeforeScheme..AfterScheme], expected_slices.scheme);
977 &url[BeforeUsername..AfterUsername],
981 &url[BeforePassword..AfterPassword],
984 assert_eq!(&url[BeforeHost..AfterHost], expected_slices.host);
985 assert_eq!(&url[BeforePort..AfterPort], expected_slices.port);
986 assert_eq!(&url[BeforePath..AfterPath], expected_slices.path);
987 assert_eq!(&url[BeforeQuery..AfterQuery], expected_slices.query);
989 &url[BeforeFragment..AfterFragment],
992 assert_eq!(&url[..AfterFragment], expected_slices.full);
1087 let base_uri = url::Url::parse(base).unwrap();
1088 let relative_uri = url::Url::parse(uri).unwrap();
1113 let base_uri = url::Url::parse(base).unwrap();
1114 let relative_uri = url::Url::parse(uri).unwrap();