• Home
  • Raw
  • Download

Lines Matching +full:path +full:- +full:parse

1 // Copyright 2013-2014 The rust-url developers.
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
14 use std::path::{Path, PathBuf};
25 let base: Url = "sc://%C3%B1".parse().unwrap(); in test_relative()
32 let base: Url = "sc://%C3%B1".parse().unwrap(); 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()
59 let mut base: Url = "moz://foo@servo/baz".parse().unwrap(); in test_set_empty_hostname()
64 base = "moz://:pass@servo/baz".parse().unwrap(); in test_set_empty_hostname()
69 base = "moz://servo/baz".parse().unwrap(); in test_set_empty_hostname()
75 ($path: expr) => {
76 assert_from_file_path!($path, $path)
78 ($path: expr, $url_path: expr) => {{
79 let url = Url::from_file_path(Path::new($path)).unwrap();
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()
123 // Invalid UTF-8 in new_path_windows_fun()
124 assert!(Url::parse("file:///C:/foo/ba%80r") in new_path_windows_fun()
129 // test windows canonicalized path in new_path_windows_fun()
130 let path = PathBuf::from(r"\\?\C:\foo\bar"); in new_path_windows_fun() localVariable
131 assert!(Url::from_file_path(path).is_ok()); in new_path_windows_fun()
133 // Percent-encoded drive letter in new_path_windows_fun()
134 let url = Url::parse("file:///C%3A/foo/bar").unwrap(); 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()
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()
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()
196 let url: Url = "file:a".parse().unwrap(); in issue_124()
197 assert_eq!(url.path(), "/a"); in issue_124()
198 let url: Url = "file:...".parse().unwrap(); in issue_124()
199 assert_eq!(url.path(), "/..."); in issue_124()
200 let url: Url = "file:..".parse().unwrap(); in issue_124()
201 assert_eq!(url.path(), "/"); in issue_124()
219 fn url(s: &str) -> Url { in test_equality()
220 let rv = s.parse().unwrap(); in test_equality()
245 // Missing path, automatically substituted. Semantically the same. 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()
293 // using IPv4-like syntax, as suggested in https://tools.ietf.org/html/rfc5952#section-4 in host_serialization()
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()
312 Some(Host::Domain("xn--n3h.net")) in test_idna()
314 assert!("https://r2---sn-huoa-cvhl.googlevideo.com/crossdomain.xml" in test_idna()
315 .parse::<Url>() in test_idna()
332 "http://slashquery.com/path/?q=something", in test_serialization()
333 "http://slashquery.com/path/?q=something", in test_serialization()
336 "http://noslashquery.com/path?q=something", in test_serialization()
337 "http://noslashquery.com/path?q=something", in test_serialization()
341 let url = Url::parse(input).unwrap(); in test_serialization()
358 form_urlencoded::parse(encoded.as_bytes()).collect::<Vec<_>>(), in test_form_urlencoded()
385 /// https://github.com/servo/rust-url/issues/61
387 let mut url = Url::parse("http://mozilla.org").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()
402 Url::parse("file:///").expect("Failed to parse path + protocol") 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()
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()
429 .extend_pairs(vec![("auth", "my-token")].into_iter()); in extend_query_pairs_then_mutate()
433 "http://localhost:6767/foo/bar?auth=my-token" in extend_query_pairs_then_mutate()
439 "http://localhost:6767/foo/bar/some_other_path?auth=my-token" 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()
454 /// https://github.com/servo/rust-url/issues/243
456 let mut url = Url::parse("https://example.net/hello").unwrap(); in test_set_host()
464 let mut url = Url::parse("foobar://example.net/hello").unwrap(); in test_set_host()
468 let mut url = Url::parse("foo://ș").unwrap(); in test_set_host()
475 // https://github.com/servo/rust-url/issues/166
478 Host::parse(".org").unwrap(), in test_leading_dots()
481 assert_eq!(Url::parse("file://./foo").unwrap().domain(), Some(".")); in test_leading_dots()
485 /// https://github.com/servo/rust-url/issues/302
490 fn hash<T: Hash>(value: &T) -> u64 { in test_origin_hash()
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()
585 ("custom-protocol://127.0.0.1:9742/", "127.0.0.1", 9742), in test_socket_addrs()
586 ("custom-protocol://127.0.0.1/", "127.0.0.1", 9743), in test_socket_addrs()
589 ("custom-protocol://[::1]:9742/", "::1", 9742), in test_socket_addrs()
590 ("custom-protocol://[::1]/", "::1", 9743), in test_socket_addrs()
593 ("custom-protocol://localhost:9742/", "localhost", 9742), in test_socket_addrs()
594 ("custom-protocol://localhost/", "localhost", 9743), in test_socket_addrs()
598 let url = url::Url::parse(url_string).unwrap(); in test_socket_addrs()
601 "custom-protocol" => Some(9743), in test_socket_addrs()
614 let mut no_base_url = Url::parse("mailto:test@example.net").unwrap(); in test_no_base_url()
621 .set_ip_host("127.0.0.1".parse().unwrap()) in test_no_base_url()
625 assert_eq!(no_base_url.path(), "%2Ffoo"); in test_no_base_url()
630 let url = Url::parse("https://127.0.0.1/").unwrap(); in test_domain()
633 let url = Url::parse("mailto:test@example.net").unwrap(); in test_domain()
636 let url = Url::parse("https://example.com/").unwrap(); in test_domain()
642 let url = Url::parse("https://example.com/products?page=2#fragment").unwrap(); in test_query()
649 let url = Url::parse("https://example.com/products").unwrap(); in test_query()
653 let url = Url::parse("https://example.com/?country=español").unwrap(); in test_query()
660 let url = Url::parse("https://example.com/products?page=2&sort=desc").unwrap(); in test_query()
676 let url = Url::parse("https://example.com/#fragment").unwrap(); in test_fragment()
679 let url = Url::parse("https://example.com/").unwrap(); in test_fragment()
685 let mut url = Url::parse("http://example.com").unwrap(); in test_set_ip_host()
687 url.set_ip_host("127.0.0.1".parse().unwrap()).unwrap(); in test_set_ip_host()
690 url.set_ip_host("::1".parse().unwrap()).unwrap(); in test_set_ip_host()
698 let mut url = Url::parse("https://existing.url").unwrap(); in test_set_href()
704 "https://user:pass@domain.com:9742/path/file.ext?key=val&key2=val2#fragment" 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()
720 ("��.��", "xn--j28h.xn--938h", "��.��"), in test_domain_encoding_quirks()
737 let url = Url::parse("https://example.com/path/file.ext?key=val&key2=val2#fragment").unwrap(); 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()
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()
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()
774 let path = url.to_file_path().unwrap(); in test_windows_unc_path() localVariable
775 assert_eq!(path.to_str(), Some(r"\\192.168.0.1\share\path\file.txt")); 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()
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()
792 .parse("http:////mozilla.org:42") in test_syntax_violation_callback()
810 .parse("http:////mozilla.org:42") in test_syntax_violation_callback_lifetimes()
817 .parse("http://mozilla.org\\path") in test_syntax_violation_callback_lifetimes()
819 assert_eq!(url.path(), "/path"); in test_syntax_violation_callback_lifetimes()
834 ("http://mozilla.org/^", NonUrlCodePoint, "non-URL code point"), in test_syntax_violation_callback_types()
845 .parse(test_case.0) in test_syntax_violation_callback_types()
862 let url = options.parse("http:////mozilla.org").unwrap(); in test_options_reuse()
865 let url = options.parse("/sub\\path").unwrap(); in test_options_reuse()
866 assert_eq!(url.as_str(), "http://mozilla.org/sub/path"); in test_options_reuse()
870 /// https://github.com/servo/rust-url/issues/505
874 use std::path::PathBuf; in test_url_from_file_path()
879 let path = u.to_file_path().unwrap(); in test_url_from_file_path() localVariable
880 assert_eq!("C:\\", path.to_str().unwrap()); in test_url_from_file_path()
883 /// https://github.com/servo/rust-url/issues/505
887 use std::path::PathBuf;
892 let path = u.to_file_path().unwrap(); localVariable
893 assert_eq!("/c:/", path.to_str().unwrap());
898 let mut db_url = url::Url::parse("postgres://postgres@localhost/").unwrap();
902 assert_eq!(db_url.path(), "/diesel_foo");
907 let mut db_url = url::Url::parse("postgres://postgres@localhost/").unwrap();
910 assert_eq!(db_url.path(), "");
913 assert_eq!(db_url.path(), "/foo");
916 assert_eq!(db_url.path(), "/bar");
922 let mut db_url = url::Url::parse("postgres://postgres@localhost/").unwrap();
926 assert_eq!(db_url.path(), "/");
929 assert_eq!(db_url.path(), "/foo");
934 let mut url: Url = "http://localhost:6767/foo/bar".parse().unwrap();
942 let mut url = Url::parse("arhttpsps:/.//eom/dae.com/\\\\t\\:").unwrap();
948 let mut url = Url::parse("m://").unwrap();
966 path: &'a str,
973 full: "https://user:pass@domain.com:9742/path/file.ext?key=val&key2=val2#fragment",
979 path: "/path/file.ext",
984 full: "https://domain.com:9742/path/file.ext#fragment",
988 path: "/path/file.ext",
993 full: "https://domain.com:9742/path/file.ext",
997 path: "/path/file.ext",
1001 full: "blob:blob-info",
1003 path: "blob-info",
1009 let url = Url::parse(expected_slices.full).unwrap();
1022 assert_eq!(&url[BeforePath..AfterPath], expected_slices.path);
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();