• Home
  • Raw
  • Download

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()
47 let mut base: Url = "file://server/share/foo/bar".parse().unwrap(); in test_set_empty_host()
51 let mut base: Url = "file://server/share/foo/bar".parse().unwrap(); in test_set_empty_host()
58 use url::quirks; in test_set_empty_hostname()
59 let mut base: Url = "moz://foo@servo/baz".parse().unwrap(); in test_set_empty_hostname()
62 "setting an empty hostname to a url with a username should fail" in test_set_empty_hostname()
67 "setting an empty hostname to a url with a password should fail" in test_set_empty_hostname()
79 let url = Url::from_file_path(Path::new($path)).unwrap(); localVariable
80 assert_eq!(url.host(), None);
81 assert_eq!(url.path(), $url_path);
82 assert_eq!(url.to_file_path(), Ok(PathBuf::from($path)));
89 assert_eq!(Url::from_file_path(Path::new("relative")), Err(())); in new_file_paths()
90 assert_eq!(Url::from_file_path(Path::new("../relative")), Err(())); in new_file_paths()
93 assert_eq!(Url::from_file_path(Path::new("relative")), Err(())); in new_file_paths()
94 assert_eq!(Url::from_file_path(Path::new(r"..\relative")), Err(())); in new_file_paths()
95 assert_eq!(Url::from_file_path(Path::new(r"\drive-relative")), Err(())); in new_file_paths()
96 assert_eq!(Url::from_file_path(Path::new(r"\\ucn\")), Err(())); in new_file_paths()
112 let url = Url::from_file_path(Path::new(OsStr::from_bytes(b"/foo/ba\x80r"))).unwrap(); in new_path_bad_utf8() localVariable
114 assert_eq!(url.to_file_path(), Ok(PathBuf::from(os_str))); in new_path_bad_utf8()
124 assert!(Url::parse("file:///C:/foo/ba%80r") in new_path_windows_fun()
131 assert!(Url::from_file_path(path).is_ok()); in new_path_windows_fun()
134 let url = Url::parse("file:///C%3A/foo/bar").unwrap(); in new_path_windows_fun() localVariable
135 assert_eq!(url.to_file_path(), Ok(PathBuf::from(r"C:\foo\bar"))); in new_path_windows_fun()
142 assert_eq!(Url::from_directory_path(Path::new("relative")), Err(())); in new_directory_paths()
143 assert_eq!(Url::from_directory_path(Path::new("../relative")), Err(())); in new_directory_paths()
145 let url = Url::from_directory_path(Path::new("/foo/bar")).unwrap(); in new_directory_paths() localVariable
146 assert_eq!(url.host(), None); in new_directory_paths()
147 assert_eq!(url.path(), "/foo/bar/"); in new_directory_paths()
150 assert_eq!(Url::from_directory_path(Path::new("relative")), Err(())); in new_directory_paths()
151 assert_eq!(Url::from_directory_path(Path::new(r"..\relative")), Err(())); in new_directory_paths()
153 Url::from_directory_path(Path::new(r"\drive-relative")), in new_directory_paths()
156 assert_eq!(Url::from_directory_path(Path::new(r"\\ucn\")), Err(())); in new_directory_paths()
158 let url = Url::from_directory_path(Path::new(r"C:\foo\bar")).unwrap(); in new_directory_paths() localVariable
159 assert_eq!(url.host(), None); in new_directory_paths()
160 assert_eq!(url.path(), "/C:/foo/bar/"); in new_directory_paths()
166 let mut special_url = "http://foobar.com".parse::<Url>().unwrap(); in path_backslash_fun()
170 let mut nonspecial_url = "thing://foobar.com".parse::<Url>().unwrap(); in path_backslash_fun()
177 assert!("http://testing.com/this".parse::<Url>().is_ok()); in from_str()
182 let url = Url::parse_with_params( in parse_with_params() localVariable
189 url.as_str(), in parse_with_params()
196 let url: Url = "file:a".parse().unwrap(); in issue_124() localVariable
197 assert_eq!(url.path(), "/a"); in issue_124()
198 let url: Url = "file:...".parse().unwrap(); in issue_124() localVariable
199 assert_eq!(url.path(), "/..."); in issue_124()
200 let url: Url = "file:..".parse().unwrap(); in issue_124() localVariable
201 assert_eq!(url.path(), "/"); in issue_124()
209 fn check_eq(a: &Url, b: &Url) { in test_equality() argument
219 fn url(s: &str) -> Url { in test_equality() function
226 let a: Url = url("https://example.com/"); in test_equality()
227 let b: Url = url("https://example.com:443/"); in test_equality()
231 let a: Url = url("http://example.com/"); in test_equality()
232 let b: Url = url("http://example.com:8080/"); in test_equality()
236 let a: Url = url("http://example.com/"); in test_equality()
237 let b: Url = url("https://example.com/"); in test_equality()
241 let a: Url = url("http://foo.com/"); in test_equality()
242 let b: Url = url("http://bar.com/"); in test_equality()
246 let a: Url = url("http://foo.com"); in test_equality()
247 let b: Url = url("http://foo.com/"); in test_equality()
254 assert_eq!(Url::parse(input).unwrap().host(), Some(host)); in host()
281 assert!(Url::parse("http://1.35.+33.49").is_err()); in host()
282 assert!(Url::parse("http://2..2.3").is_err()); in host()
283 assert!(Url::parse("http://42.0x1232131").is_err()); in host()
284 assert!(Url::parse("http://192.168.0.257").is_err()); in host()
294 // but https://url.spec.whatwg.org/#concept-ipv6-serializer specifies not to. in host_serialization()
298 Url::parse("http://[0::2]").unwrap().host_str(), in host_serialization()
302 Url::parse("http://[0::ffff:0:2]").unwrap().host_str(), in host_serialization()
309 assert!("http://goșu.ro".parse::<Url>().is_ok()); in test_idna()
311 Url::parse("http://☃.net/").unwrap().host(), in test_idna()
315 .parse::<Url>() in test_idna()
341 let url = Url::parse(input).unwrap(); in test_serialization() localVariable
342 assert_eq!(url.as_str(), result); in test_serialization()
385 /// https://github.com/servo/rust-url/issues/61
387 let mut url = Url::parse("http://mozilla.org").unwrap(); in issue_61() localVariable
388 url.set_scheme("https").unwrap(); in issue_61()
389 assert_eq!(url.port(), None); in issue_61()
390 assert_eq!(url.port_or_known_default(), Some(443)); in issue_61()
391 url.check_invariants().unwrap(); in issue_61()
396 /// https://github.com/servo/rust-url/issues/197
398 let mut url = Url::from_file_path("/").expect("Failed to parse path"); in issue_197() localVariable
399 url.check_invariants().unwrap(); in issue_197()
401 url, in issue_197()
402 Url::parse("file:///").expect("Failed to parse path + protocol") in issue_197()
404 url.path_segments_mut() in issue_197()
411 Url::parse("mailto:").unwrap().cannot_be_a_base(); in issue_241()
415 /// https://github.com/servo/rust-url/issues/222
417 let mut url: Url = "http://localhost:6767/foo/bar?a=b".parse().unwrap(); in append_trailing_slash() localVariable
418 url.check_invariants().unwrap(); in append_trailing_slash()
419 url.path_segments_mut().unwrap().push(""); in append_trailing_slash()
420 url.check_invariants().unwrap(); in append_trailing_slash()
421 assert_eq!(url.to_string(), "http://localhost:6767/foo/bar/?a=b"); in append_trailing_slash()
425 /// https://github.com/servo/rust-url/issues/227
427 let mut url: Url = "http://localhost:6767/foo/bar".parse().unwrap(); in extend_query_pairs_then_mutate() localVariable
428 url.query_pairs_mut() in extend_query_pairs_then_mutate()
430 url.check_invariants().unwrap(); in extend_query_pairs_then_mutate()
432 url.to_string(), in extend_query_pairs_then_mutate()
435 url.path_segments_mut().unwrap().push("some_other_path"); in extend_query_pairs_then_mutate()
436 url.check_invariants().unwrap(); in extend_query_pairs_then_mutate()
438 url.to_string(), in extend_query_pairs_then_mutate()
444 /// https://github.com/servo/rust-url/issues/222
446 let mut url: Url = "http://localhost:6767/foo/bar?a=b".parse().unwrap(); in append_empty_segment_then_mutate() localVariable
447 url.check_invariants().unwrap(); in append_empty_segment_then_mutate()
448 url.path_segments_mut().unwrap().push("").pop(); in append_empty_segment_then_mutate()
449 url.check_invariants().unwrap(); in append_empty_segment_then_mutate()
450 assert_eq!(url.to_string(), "http://localhost:6767/foo/bar?a=b"); in append_empty_segment_then_mutate()
454 /// https://github.com/servo/rust-url/issues/243
456 let mut url = Url::parse("https://example.net/hello").unwrap(); in test_set_host() localVariable
457 url.set_host(Some("foo.com")).unwrap(); in test_set_host()
458 assert_eq!(url.as_str(), "https://foo.com/hello"); in test_set_host()
459 assert!(url.set_host(None).is_err()); in test_set_host()
460 assert_eq!(url.as_str(), "https://foo.com/hello"); in test_set_host()
461 assert!(url.set_host(Some("")).is_err()); in test_set_host()
462 assert_eq!(url.as_str(), "https://foo.com/hello"); in test_set_host()
464 let mut url = Url::parse("foobar://example.net/hello").unwrap(); in test_set_host() localVariable
465 url.set_host(None).unwrap(); in test_set_host()
466 assert_eq!(url.as_str(), "foobar:/hello"); in test_set_host()
468 let mut url = Url::parse("foo://ș").unwrap(); in test_set_host() localVariable
469 assert_eq!(url.as_str(), "foo://%C8%99"); in test_set_host()
470 url.set_host(Some("goșu.ro")).unwrap(); in test_set_host()
471 assert_eq!(url.as_str(), "foo://go%C8%99u.ro"); in test_set_host()
475 // https://github.com/servo/rust-url/issues/166
481 assert_eq!(Url::parse("file://./foo").unwrap().domain(), Some(".")); in test_leading_dots()
485 /// https://github.com/servo/rust-url/issues/302
496 let origin = &Url::parse("http://example.net/").unwrap().origin(); in test_origin_hash()
499 Url::parse("http://example.net:80/").unwrap().origin(), in test_origin_hash()
500 Url::parse("http://example.net:81/").unwrap().origin(), in test_origin_hash()
501 Url::parse("http://example.net").unwrap().origin(), in test_origin_hash()
502 Url::parse("http://example.net/hello").unwrap().origin(), in test_origin_hash()
503 Url::parse("https://example.net").unwrap().origin(), in test_origin_hash()
504 Url::parse("ftp://example.net").unwrap().origin(), in test_origin_hash()
505 Url::parse("file://example.net").unwrap().origin(), in test_origin_hash()
506 Url::parse("http://user@example.net/").unwrap().origin(), in test_origin_hash()
507 Url::parse("http://user:pass@example.net/") in test_origin_hash()
520 let opaque_origin = Url::parse("file://example.net").unwrap().origin(); in test_origin_hash()
521 let same_opaque_origin = Url::parse("file://example.net").unwrap().origin(); in test_origin_hash()
522 let other_opaque_origin = Url::parse("file://other").unwrap().origin(); in test_origin_hash()
530 let origin = &Url::parse("http://example.net/").unwrap().origin(); in test_origin_blob_equality()
531 let blob_origin = &Url::parse("blob:http://example.net/").unwrap().origin(); in test_origin_blob_equality()
539 assert!(!&Url::parse("blob:malformed//").unwrap().origin().is_tuple()) in test_origin_opaque()
551 let origin = Url::parse(unicode_url).unwrap().origin(); in test_origin_unicode_serialization()
556 Url::parse("http://example.net/").unwrap().origin(), in test_origin_unicode_serialization()
557 Url::parse("http://example.net:80/").unwrap().origin(), in test_origin_unicode_serialization()
558 Url::parse("http://example.net:81/").unwrap().origin(), in test_origin_unicode_serialization()
559 Url::parse("http://example.net").unwrap().origin(), in test_origin_unicode_serialization()
560 Url::parse("http://example.net/hello").unwrap().origin(), in test_origin_unicode_serialization()
561 Url::parse("https://example.net").unwrap().origin(), in test_origin_unicode_serialization()
562 Url::parse("ftp://example.net").unwrap().origin(), in test_origin_unicode_serialization()
563 Url::parse("file://example.net").unwrap().origin(), in test_origin_unicode_serialization()
564 Url::parse("http://user@example.net/").unwrap().origin(), in test_origin_unicode_serialization()
565 Url::parse("http://user:pass@example.net/") in test_origin_unicode_serialization()
568 Url::parse("http://127.0.0.1").unwrap().origin(), in test_origin_unicode_serialization()
598 let url = url::Url::parse(url_string).unwrap(); in test_socket_addrs() localVariable
599 let addrs = url in test_socket_addrs()
600 .socket_addrs(|| match url.scheme() { in test_socket_addrs()
614 let mut no_base_url = Url::parse("mailto:test@example.net").unwrap(); in test_no_base_url()
630 let url = Url::parse("https://127.0.0.1/").unwrap(); in test_domain() localVariable
631 assert_eq!(url.domain(), None); in test_domain()
633 let url = Url::parse("mailto:test@example.net").unwrap(); in test_domain() localVariable
634 assert_eq!(url.domain(), None); in test_domain()
636 let url = Url::parse("https://example.com/").unwrap(); in test_domain() localVariable
637 assert_eq!(url.domain(), Some("example.com")); in test_domain()
642 let url = Url::parse("https://example.com/products?page=2#fragment").unwrap(); in test_query() localVariable
643 assert_eq!(url.query(), Some("page=2")); in test_query()
645 url.query_pairs().next(), in test_query()
649 let url = Url::parse("https://example.com/products").unwrap(); in test_query() localVariable
650 assert!(url.query().is_none()); in test_query()
651 assert_eq!(url.query_pairs().count(), 0); in test_query()
653 let url = Url::parse("https://example.com/?country=español").unwrap(); in test_query() localVariable
654 assert_eq!(url.query(), Some("country=espa%C3%B1ol")); in test_query()
656 url.query_pairs().next(), in test_query()
660 let url = Url::parse("https://example.com/products?page=2&sort=desc").unwrap(); in test_query() localVariable
661 assert_eq!(url.query(), Some("page=2&sort=desc")); in test_query()
662 let mut pairs = url.query_pairs(); in test_query()
676 let url = Url::parse("https://example.com/#fragment").unwrap(); in test_fragment() localVariable
677 assert_eq!(url.fragment(), Some("fragment")); in test_fragment()
679 let url = Url::parse("https://example.com/").unwrap(); in test_fragment() localVariable
680 assert_eq!(url.fragment(), None); in test_fragment()
685 let mut url = Url::parse("http://example.com").unwrap(); in test_set_ip_host() localVariable
687 url.set_ip_host("127.0.0.1".parse().unwrap()).unwrap(); in test_set_ip_host()
688 assert_eq!(url.host_str(), Some("127.0.0.1")); in test_set_ip_host()
690 url.set_ip_host("::1".parse().unwrap()).unwrap(); in test_set_ip_host()
691 assert_eq!(url.host_str(), Some("[::1]")); in test_set_ip_host()
696 use url::quirks::set_href; in test_set_href()
698 let mut url = Url::parse("https://existing.url").unwrap(); in test_set_href() localVariable
700 assert!(set_href(&mut url, "mal//formed").is_err()); in test_set_href()
703 &mut url, in test_set_href()
708 url, in test_set_href()
709 Url::parse("https://user:pass@domain.com:9742/path/file.ext?key=val&key2=val2#fragment") in test_set_href()
716 use url::quirks::{domain_to_ascii, domain_to_unicode}; in test_domain_encoding_quirks()
725 for url in &data { in test_domain_encoding_quirks()
726 assert_eq!(domain_to_ascii(url.0), url.1); in test_domain_encoding_quirks()
727 assert_eq!(domain_to_unicode(url.0), url.2); in test_domain_encoding_quirks()
734 use url::quirks::internal_components; in test_expose_internals()
735 use url::quirks::InternalComponents; in test_expose_internals()
737 let url = Url::parse("https://example.com/path/file.ext?key=val&key2=val2#fragment").unwrap(); in test_expose_internals() localVariable
747 } = internal_components(&url); in test_expose_internals()
765 let url = Url::from_file_path(Path::new(r"\\host\share\path\file.txt")).unwrap(); in test_windows_unc_path() localVariable
766 assert_eq!(url.as_str(), "file://host/share/path/file.txt"); in test_windows_unc_path()
768 let url = Url::from_file_path(Path::new(r"\\höst\share\path\file.txt")).unwrap(); in test_windows_unc_path() localVariable
769 assert_eq!(url.as_str(), "file://xn--hst-sna/share/path/file.txt"); in test_windows_unc_path()
771 let url = Url::from_file_path(Path::new(r"\\192.168.0.1\share\path\file.txt")).unwrap(); in test_windows_unc_path() localVariable
772 assert_eq!(url.host(), Some(Host::Ipv4(Ipv4Addr::new(192, 168, 0, 1)))); in test_windows_unc_path()
774 let path = url.to_file_path().unwrap(); in test_windows_unc_path()
778 let url = Url::from_file_path(Path::new(r"\\?\UNC\host\share\path\file.txt")).unwrap(); in test_windows_unc_path() localVariable
779 assert_eq!(url.as_str(), "file://host/share/path/file.txt"); in test_windows_unc_path()
782 let url = Url::from_file_path(Path::new(r"\\.\some\path\file.txt")); in test_windows_unc_path() localVariable
783 assert!(url.is_err()); in test_windows_unc_path()
788 use url::SyntaxViolation::*; in test_syntax_violation_callback()
790 let url = Url::options() in test_syntax_violation_callback() localVariable
794 assert_eq!(url.port(), Some(42)); in test_syntax_violation_callback()
804 use url::SyntaxViolation::*; in test_syntax_violation_callback_lifetimes()
808 let url = Url::options() in test_syntax_violation_callback_lifetimes() localVariable
812 assert_eq!(url.port(), Some(42)); in test_syntax_violation_callback_lifetimes()
815 let url = Url::options() in test_syntax_violation_callback_lifetimes() localVariable
819 assert_eq!(url.path(), "/path"); in test_syntax_violation_callback_lifetimes()
825 use url::SyntaxViolation::*; in test_syntax_violation_callback_types()
830 …ntials, "embedding authentication information (username or password) in an URL is not recommended"… in test_syntax_violation_callback_types()
834 ("http://mozilla.org/^", NonUrlCodePoint, "non-URL code point"), in test_syntax_violation_callback_types()
835 …("http://mozilla.org/#\x000", NullInFragment, "NULL characters are ignored in URL fragment identif… in test_syntax_violation_callback_types()
843 Url::options() in test_syntax_violation_callback_types()
857 use url::SyntaxViolation::*; in test_options_reuse()
861 let options = Url::options().syntax_violation_callback(Some(&vfn)); in test_options_reuse()
862 let url = options.parse("http:////mozilla.org").unwrap(); in test_options_reuse() localVariable
864 let options = options.base_url(Some(&url)); in test_options_reuse()
865 let url = options.parse("/sub\\path").unwrap(); in test_options_reuse() localVariable
866 assert_eq!(url.as_str(), "http://mozilla.org/sub/path"); in test_options_reuse()
870 /// https://github.com/servo/rust-url/issues/505
875 use url::Url; in test_url_from_file_path()
878 let u = Url::from_file_path(p).unwrap(); in test_url_from_file_path()
883 /// https://github.com/servo/rust-url/issues/505
888 use url::Url;
891 let u = Url::from_file_path(p).unwrap();
898 let mut db_url = url::Url::parse("postgres://postgres@localhost/").unwrap();
907 let mut db_url = url::Url::parse("postgres://postgres@localhost/").unwrap();
922 let mut db_url = url::Url::parse("postgres://postgres@localhost/").unwrap();
934 let mut url: Url = "http://localhost:6767/foo/bar".parse().unwrap(); localVariable
935 let result = url.set_scheme("file");
936 assert_eq!(url.to_string(), "http://localhost:6767/foo/bar");
942 let mut url = Url::parse("arhttpsps:/.//eom/dae.com/\\\\t\\:").unwrap(); localVariable
943 url::quirks::set_hostname(&mut url, "//eom/datcom/\\\\t\\://eom/data.cs").unwrap();
948 let mut url = Url::parse("m://").unwrap(); localVariable
949 let mut segments = url.path_segments_mut().unwrap();
956 use url::Position::*;
1009 let url = Url::parse(expected_slices.full).unwrap(); localVariable
1010 assert_eq!(&url[..], expected_slices.full);
1011 assert_eq!(&url[BeforeScheme..AfterScheme], expected_slices.scheme);
1013 &url[BeforeUsername..AfterUsername],
1017 &url[BeforePassword..AfterPassword],
1020 assert_eq!(&url[BeforeHost..AfterHost], expected_slices.host);
1021 assert_eq!(&url[BeforePort..AfterPort], expected_slices.port);
1022 assert_eq!(&url[BeforePath..AfterPath], expected_slices.path);
1023 assert_eq!(&url[BeforeQuery..AfterQuery], expected_slices.query);
1025 &url[BeforeFragment..AfterFragment],
1028 assert_eq!(&url[..AfterFragment], expected_slices.full);
1133 let base_uri = url::Url::parse(base).unwrap();
1134 let relative_uri = url::Url::parse(uri).unwrap();
1159 let base_uri = url::Url::parse(base).unwrap();
1160 let relative_uri = url::Url::parse(uri).unwrap();