unit.rs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. // Copyright 2013-2014 The rust-url developers.
  2. //
  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
  6. // option. This file may not be copied, modified, or distributed
  7. // except according to those terms.
  8. //! Unit tests
  9. #[macro_use]
  10. extern crate url;
  11. use std::ascii::AsciiExt;
  12. use std::borrow::Cow;
  13. use std::cell::{Cell, RefCell};
  14. use std::net::{Ipv4Addr, Ipv6Addr};
  15. use std::path::{Path, PathBuf};
  16. use url::{Host, HostAndPort, Url, form_urlencoded};
  17. #[test]
  18. fn size() {
  19. use std::mem::size_of;
  20. assert_eq!(size_of::<Url>(), size_of::<Option<Url>>());
  21. }
  22. macro_rules! assert_from_file_path {
  23. ($path: expr) => { assert_from_file_path!($path, $path) };
  24. ($path: expr, $url_path: expr) => {{
  25. let url = Url::from_file_path(Path::new($path)).unwrap();
  26. assert_eq!(url.host(), None);
  27. assert_eq!(url.path(), $url_path);
  28. assert_eq!(url.to_file_path(), Ok(PathBuf::from($path)));
  29. }};
  30. }
  31. #[test]
  32. fn new_file_paths() {
  33. if cfg!(unix) {
  34. assert_eq!(Url::from_file_path(Path::new("relative")), Err(()));
  35. assert_eq!(Url::from_file_path(Path::new("../relative")), Err(()));
  36. }
  37. if cfg!(windows) {
  38. assert_eq!(Url::from_file_path(Path::new("relative")), Err(()));
  39. assert_eq!(Url::from_file_path(Path::new(r"..\relative")), Err(()));
  40. assert_eq!(Url::from_file_path(Path::new(r"\drive-relative")), Err(()));
  41. assert_eq!(Url::from_file_path(Path::new(r"\\ucn\")), Err(()));
  42. }
  43. if cfg!(unix) {
  44. assert_from_file_path!("/foo/bar");
  45. assert_from_file_path!("/foo/ba\0r", "/foo/ba%00r");
  46. assert_from_file_path!("/foo/ba%00r", "/foo/ba%2500r");
  47. }
  48. }
  49. #[test]
  50. #[cfg(unix)]
  51. fn new_path_bad_utf8() {
  52. use std::ffi::OsStr;
  53. use std::os::unix::prelude::*;
  54. let url = Url::from_file_path(Path::new(OsStr::from_bytes(b"/foo/ba\x80r"))).unwrap();
  55. let os_str = OsStr::from_bytes(b"/foo/ba\x80r");
  56. assert_eq!(url.to_file_path(), Ok(PathBuf::from(os_str)));
  57. }
  58. #[test]
  59. fn new_path_windows_fun() {
  60. if cfg!(windows) {
  61. assert_from_file_path!(r"C:\foo\bar", "/C:/foo/bar");
  62. assert_from_file_path!("C:\\foo\\ba\0r", "/C:/foo/ba%00r");
  63. // Invalid UTF-8
  64. assert!(Url::parse("file:///C:/foo/ba%80r").unwrap().to_file_path().is_err());
  65. // test windows canonicalized path
  66. let path = PathBuf::from(r"\\?\C:\foo\bar");
  67. assert!(Url::from_file_path(path).is_ok());
  68. // Percent-encoded drive letter
  69. let url = Url::parse("file:///C%3A/foo/bar").unwrap();
  70. assert_eq!(url.to_file_path(), Ok(PathBuf::from(r"C:\foo\bar")));
  71. }
  72. }
  73. #[test]
  74. fn new_directory_paths() {
  75. if cfg!(unix) {
  76. assert_eq!(Url::from_directory_path(Path::new("relative")), Err(()));
  77. assert_eq!(Url::from_directory_path(Path::new("../relative")), Err(()));
  78. let url = Url::from_directory_path(Path::new("/foo/bar")).unwrap();
  79. assert_eq!(url.host(), None);
  80. assert_eq!(url.path(), "/foo/bar/");
  81. }
  82. if cfg!(windows) {
  83. assert_eq!(Url::from_directory_path(Path::new("relative")), Err(()));
  84. assert_eq!(Url::from_directory_path(Path::new(r"..\relative")), Err(()));
  85. assert_eq!(Url::from_directory_path(Path::new(r"\drive-relative")), Err(()));
  86. assert_eq!(Url::from_directory_path(Path::new(r"\\ucn\")), Err(()));
  87. let url = Url::from_directory_path(Path::new(r"C:\foo\bar")).unwrap();
  88. assert_eq!(url.host(), None);
  89. assert_eq!(url.path(), "/C:/foo/bar/");
  90. }
  91. }
  92. #[test]
  93. fn path_backslash_fun() {
  94. let mut special_url = "http://foobar.com".parse::<Url>().unwrap();
  95. special_url.path_segments_mut().unwrap().push("foo\\bar");
  96. assert_eq!(special_url.as_str(), "http://foobar.com/foo%5Cbar");
  97. let mut nonspecial_url = "thing://foobar.com".parse::<Url>().unwrap();
  98. nonspecial_url.path_segments_mut().unwrap().push("foo\\bar");
  99. assert_eq!(nonspecial_url.as_str(), "thing://foobar.com/foo\\bar");
  100. }
  101. #[test]
  102. fn from_str() {
  103. assert!("http://testing.com/this".parse::<Url>().is_ok());
  104. }
  105. #[test]
  106. fn parse_with_params() {
  107. let url = Url::parse_with_params("http://testing.com/this?dont=clobberme",
  108. &[("lang", "rust")]).unwrap();
  109. assert_eq!(url.as_str(), "http://testing.com/this?dont=clobberme&lang=rust");
  110. }
  111. #[test]
  112. fn issue_124() {
  113. let url: Url = "file:a".parse().unwrap();
  114. assert_eq!(url.path(), "/a");
  115. let url: Url = "file:...".parse().unwrap();
  116. assert_eq!(url.path(), "/...");
  117. let url: Url = "file:..".parse().unwrap();
  118. assert_eq!(url.path(), "/");
  119. }
  120. #[test]
  121. fn test_equality() {
  122. use std::hash::{Hash, Hasher};
  123. use std::collections::hash_map::DefaultHasher;
  124. fn check_eq(a: &Url, b: &Url) {
  125. assert_eq!(a, b);
  126. let mut h1 = DefaultHasher::new();
  127. a.hash(&mut h1);
  128. let mut h2 = DefaultHasher::new();
  129. b.hash(&mut h2);
  130. assert_eq!(h1.finish(), h2.finish());
  131. }
  132. fn url(s: &str) -> Url {
  133. let rv = s.parse().unwrap();
  134. check_eq(&rv, &rv);
  135. rv
  136. }
  137. // Doesn't care if default port is given.
  138. let a: Url = url("https://example.com/");
  139. let b: Url = url("https://example.com:443/");
  140. check_eq(&a, &b);
  141. // Different ports
  142. let a: Url = url("http://example.com/");
  143. let b: Url = url("http://example.com:8080/");
  144. assert!(a != b, "{:?} != {:?}", a, b);
  145. // Different scheme
  146. let a: Url = url("http://example.com/");
  147. let b: Url = url("https://example.com/");
  148. assert_ne!(a, b);
  149. // Different host
  150. let a: Url = url("http://foo.com/");
  151. let b: Url = url("http://bar.com/");
  152. assert_ne!(a, b);
  153. // Missing path, automatically substituted. Semantically the same.
  154. let a: Url = url("http://foo.com");
  155. let b: Url = url("http://foo.com/");
  156. check_eq(&a, &b);
  157. }
  158. #[test]
  159. fn host() {
  160. fn assert_host(input: &str, host: Host<&str>) {
  161. assert_eq!(Url::parse(input).unwrap().host(), Some(host));
  162. }
  163. assert_host("http://www.mozilla.org", Host::Domain("www.mozilla.org"));
  164. assert_host("http://1.35.33.49", Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)));
  165. assert_host("http://[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]", Host::Ipv6(Ipv6Addr::new(
  166. 0x2001, 0x0db8, 0x85a3, 0x08d3, 0x1319, 0x8a2e, 0x0370, 0x7344)));
  167. assert_host("http://1.35.+33.49", Host::Domain("1.35.+33.49"));
  168. assert_host("http://[::]", Host::Ipv6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)));
  169. assert_host("http://[::1]", Host::Ipv6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)));
  170. assert_host("http://0x1.0X23.0x21.061", Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)));
  171. assert_host("http://0x1232131", Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)));
  172. assert_host("http://111", Host::Ipv4(Ipv4Addr::new(0, 0, 0, 111)));
  173. assert_host("http://2..2.3", Host::Domain("2..2.3"));
  174. assert!(Url::parse("http://42.0x1232131").is_err());
  175. assert!(Url::parse("http://192.168.0.257").is_err());
  176. }
  177. #[test]
  178. fn host_serialization() {
  179. // libstd’s `Display for Ipv6Addr` serializes 0:0:0:0:0:0:_:_ and 0:0:0:0:0:ffff:_:_
  180. // using IPv4-like syntax, as suggested in https://tools.ietf.org/html/rfc5952#section-4
  181. // but https://url.spec.whatwg.org/#concept-ipv6-serializer specifies not to.
  182. // Not [::0.0.0.2] / [::ffff:0.0.0.2]
  183. assert_eq!(Url::parse("http://[0::2]").unwrap().host_str(), Some("[::2]"));
  184. assert_eq!(Url::parse("http://[0::ffff:0:2]").unwrap().host_str(), Some("[::ffff:0:2]"));
  185. }
  186. #[test]
  187. fn test_idna() {
  188. assert!("http://goșu.ro".parse::<Url>().is_ok());
  189. assert_eq!(Url::parse("http://☃.net/").unwrap().host(), Some(Host::Domain("xn--n3h.net")));
  190. assert!("https://r2---sn-huoa-cvhl.googlevideo.com/crossdomain.xml".parse::<Url>().is_ok());
  191. }
  192. #[test]
  193. fn test_serialization() {
  194. let data = [
  195. ("http://example.com/", "http://example.com/"),
  196. ("http://addslash.com", "http://addslash.com/"),
  197. ("http://@emptyuser.com/", "http://emptyuser.com/"),
  198. ("http://:@emptypass.com/", "http://emptypass.com/"),
  199. ("http://user@user.com/", "http://user@user.com/"),
  200. ("http://user:pass@userpass.com/", "http://user:pass@userpass.com/"),
  201. ("http://slashquery.com/path/?q=something", "http://slashquery.com/path/?q=something"),
  202. ("http://noslashquery.com/path?q=something", "http://noslashquery.com/path?q=something")
  203. ];
  204. for &(input, result) in &data {
  205. let url = Url::parse(input).unwrap();
  206. assert_eq!(url.as_str(), result);
  207. }
  208. }
  209. #[test]
  210. fn test_form_urlencoded() {
  211. let pairs: &[(Cow<str>, Cow<str>)] = &[
  212. ("foo".into(), "é&".into()),
  213. ("bar".into(), "".into()),
  214. ("foo".into(), "#".into())
  215. ];
  216. let encoded = form_urlencoded::Serializer::new(String::new()).extend_pairs(pairs).finish();
  217. assert_eq!(encoded, "foo=%C3%A9%26&bar=&foo=%23");
  218. assert_eq!(form_urlencoded::parse(encoded.as_bytes()).collect::<Vec<_>>(), pairs.to_vec());
  219. }
  220. #[test]
  221. fn test_form_serialize() {
  222. let encoded = form_urlencoded::Serializer::new(String::new())
  223. .append_pair("foo", "é&")
  224. .append_pair("bar", "")
  225. .append_pair("foo", "#")
  226. .finish();
  227. assert_eq!(encoded, "foo=%C3%A9%26&bar=&foo=%23");
  228. }
  229. #[test]
  230. fn form_urlencoded_custom_encoding_override() {
  231. let encoded = form_urlencoded::Serializer::new(String::new())
  232. .custom_encoding_override(|s| s.as_bytes().to_ascii_uppercase().into())
  233. .append_pair("foo", "bar")
  234. .finish();
  235. assert_eq!(encoded, "FOO=BAR");
  236. }
  237. #[test]
  238. fn host_and_port_display() {
  239. assert_eq!(
  240. format!(
  241. "{}",
  242. HostAndPort{ host: Host::Domain("www.mozilla.org"), port: 80}
  243. ),
  244. "www.mozilla.org:80"
  245. );
  246. assert_eq!(
  247. format!(
  248. "{}",
  249. HostAndPort::<String>{ host: Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)), port: 65535 }
  250. ),
  251. "1.35.33.49:65535"
  252. );
  253. assert_eq!(
  254. format!(
  255. "{}",
  256. HostAndPort::<String>{
  257. host: Host::Ipv6(Ipv6Addr::new(
  258. 0x2001, 0x0db8, 0x85a3, 0x08d3, 0x1319, 0x8a2e, 0x0370, 0x7344
  259. )),
  260. port: 1337
  261. })
  262. ,
  263. "[2001:db8:85a3:8d3:1319:8a2e:370:7344]:1337"
  264. )
  265. }
  266. #[test]
  267. /// https://github.com/servo/rust-url/issues/61
  268. fn issue_61() {
  269. let mut url = Url::parse("http://mozilla.org").unwrap();
  270. url.set_scheme("https").unwrap();
  271. assert_eq!(url.port(), None);
  272. assert_eq!(url.port_or_known_default(), Some(443));
  273. url.check_invariants().unwrap();
  274. }
  275. #[test]
  276. #[cfg(not(windows))]
  277. /// https://github.com/servo/rust-url/issues/197
  278. fn issue_197() {
  279. let mut url = Url::from_file_path("/").expect("Failed to parse path");
  280. url.check_invariants().unwrap();
  281. assert_eq!(url, Url::parse("file:///").expect("Failed to parse path + protocol"));
  282. url.path_segments_mut().expect("path_segments_mut").pop_if_empty();
  283. }
  284. #[test]
  285. fn issue_241() {
  286. Url::parse("mailto:").unwrap().cannot_be_a_base();
  287. }
  288. #[test]
  289. /// https://github.com/servo/rust-url/issues/222
  290. fn append_trailing_slash() {
  291. let mut url: Url = "http://localhost:6767/foo/bar?a=b".parse().unwrap();
  292. url.check_invariants().unwrap();
  293. url.path_segments_mut().unwrap().push("");
  294. url.check_invariants().unwrap();
  295. assert_eq!(url.to_string(), "http://localhost:6767/foo/bar/?a=b");
  296. }
  297. #[test]
  298. /// https://github.com/servo/rust-url/issues/227
  299. fn extend_query_pairs_then_mutate() {
  300. let mut url: Url = "http://localhost:6767/foo/bar".parse().unwrap();
  301. url.query_pairs_mut().extend_pairs(vec![ ("auth", "my-token") ].into_iter());
  302. url.check_invariants().unwrap();
  303. assert_eq!(url.to_string(), "http://localhost:6767/foo/bar?auth=my-token");
  304. url.path_segments_mut().unwrap().push("some_other_path");
  305. url.check_invariants().unwrap();
  306. assert_eq!(url.to_string(), "http://localhost:6767/foo/bar/some_other_path?auth=my-token");
  307. }
  308. #[test]
  309. /// https://github.com/servo/rust-url/issues/222
  310. fn append_empty_segment_then_mutate() {
  311. let mut url: Url = "http://localhost:6767/foo/bar?a=b".parse().unwrap();
  312. url.check_invariants().unwrap();
  313. url.path_segments_mut().unwrap().push("").pop();
  314. url.check_invariants().unwrap();
  315. assert_eq!(url.to_string(), "http://localhost:6767/foo/bar?a=b");
  316. }
  317. #[test]
  318. /// https://github.com/servo/rust-url/issues/243
  319. fn test_set_host() {
  320. let mut url = Url::parse("https://example.net/hello").unwrap();
  321. url.set_host(Some("foo.com")).unwrap();
  322. assert_eq!(url.as_str(), "https://foo.com/hello");
  323. assert!(url.set_host(None).is_err());
  324. assert_eq!(url.as_str(), "https://foo.com/hello");
  325. assert!(url.set_host(Some("")).is_err());
  326. assert_eq!(url.as_str(), "https://foo.com/hello");
  327. let mut url = Url::parse("foobar://example.net/hello").unwrap();
  328. url.set_host(None).unwrap();
  329. assert_eq!(url.as_str(), "foobar:/hello");
  330. let mut url = Url::parse("foo://ș").unwrap();
  331. assert_eq!(url.as_str(), "foo://%C8%99/");
  332. url.set_host(Some("goșu.ro")).unwrap();
  333. assert_eq!(url.as_str(), "foo://go%C8%99u.ro/");
  334. }
  335. #[test]
  336. // https://github.com/servo/rust-url/issues/166
  337. fn test_leading_dots() {
  338. assert_eq!(Host::parse(".org").unwrap(), Host::Domain(".org".to_owned()));
  339. assert_eq!(Url::parse("file://./foo").unwrap().domain(), Some("."));
  340. }
  341. // This is testing that the macro produces buildable code when invoked
  342. // inside both a module and a function
  343. #[test]
  344. fn define_encode_set_scopes() {
  345. use url::percent_encoding::{utf8_percent_encode, SIMPLE_ENCODE_SET};
  346. define_encode_set! {
  347. /// This encode set is used in the URL parser for query strings.
  348. pub QUERY_ENCODE_SET = [SIMPLE_ENCODE_SET] | {' ', '"', '#', '<', '>'}
  349. }
  350. assert_eq!(utf8_percent_encode("foo bar", QUERY_ENCODE_SET).collect::<String>(), "foo%20bar");
  351. mod m {
  352. use url::percent_encoding::{utf8_percent_encode, SIMPLE_ENCODE_SET};
  353. define_encode_set! {
  354. /// This encode set is used in the URL parser for query strings.
  355. pub QUERY_ENCODE_SET = [SIMPLE_ENCODE_SET] | {' ', '"', '#', '<', '>'}
  356. }
  357. pub fn test() {
  358. assert_eq!(utf8_percent_encode("foo bar", QUERY_ENCODE_SET).collect::<String>(), "foo%20bar");
  359. }
  360. }
  361. m::test();
  362. }
  363. #[test]
  364. /// https://github.com/servo/rust-url/issues/302
  365. fn test_origin_hash() {
  366. use std::hash::{Hash,Hasher};
  367. use std::collections::hash_map::DefaultHasher;
  368. fn hash<T: Hash>(value: &T) -> u64 {
  369. let mut hasher = DefaultHasher::new();
  370. value.hash(&mut hasher);
  371. hasher.finish()
  372. }
  373. let origin = &Url::parse("http://example.net/").unwrap().origin();
  374. let origins_to_compare = [
  375. Url::parse("http://example.net:80/").unwrap().origin(),
  376. Url::parse("http://example.net:81/").unwrap().origin(),
  377. Url::parse("http://example.net").unwrap().origin(),
  378. Url::parse("http://example.net/hello").unwrap().origin(),
  379. Url::parse("https://example.net").unwrap().origin(),
  380. Url::parse("ftp://example.net").unwrap().origin(),
  381. Url::parse("file://example.net").unwrap().origin(),
  382. Url::parse("http://user@example.net/").unwrap().origin(),
  383. Url::parse("http://user:pass@example.net/").unwrap().origin(),
  384. ];
  385. for origin_to_compare in &origins_to_compare {
  386. if origin == origin_to_compare {
  387. assert_eq!(hash(origin), hash(origin_to_compare));
  388. } else {
  389. assert_ne!(hash(origin), hash(origin_to_compare));
  390. }
  391. }
  392. let opaque_origin = Url::parse("file://example.net").unwrap().origin();
  393. let same_opaque_origin = Url::parse("file://example.net").unwrap().origin();
  394. let other_opaque_origin = Url::parse("file://other").unwrap().origin();
  395. assert_ne!(hash(&opaque_origin), hash(&same_opaque_origin));
  396. assert_ne!(hash(&opaque_origin), hash(&other_opaque_origin));
  397. }
  398. #[test]
  399. fn test_windows_unc_path() {
  400. if !cfg!(windows) {
  401. return
  402. }
  403. let url = Url::from_file_path(Path::new(r"\\host\share\path\file.txt")).unwrap();
  404. assert_eq!(url.as_str(), "file://host/share/path/file.txt");
  405. let url = Url::from_file_path(Path::new(r"\\höst\share\path\file.txt")).unwrap();
  406. assert_eq!(url.as_str(), "file://xn--hst-sna/share/path/file.txt");
  407. let url = Url::from_file_path(Path::new(r"\\192.168.0.1\share\path\file.txt")).unwrap();
  408. assert_eq!(url.host(), Some(Host::Ipv4(Ipv4Addr::new(192, 168, 0, 1))));
  409. let path = url.to_file_path().unwrap();
  410. assert_eq!(path.to_str(), Some(r"\\192.168.0.1\share\path\file.txt"));
  411. // Another way to write these:
  412. let url = Url::from_file_path(Path::new(r"\\?\UNC\host\share\path\file.txt")).unwrap();
  413. assert_eq!(url.as_str(), "file://host/share/path/file.txt");
  414. // Paths starting with "\\.\" (Local Device Paths) are intentionally not supported.
  415. let url = Url::from_file_path(Path::new(r"\\.\some\path\file.txt"));
  416. assert!(url.is_err());
  417. }
  418. #[test]
  419. fn test_syntax_violation_callback() {
  420. use url::SyntaxViolation::*;
  421. let violation = Cell::new(None);
  422. let url = Url::options()
  423. .syntax_violation_callback(Some(&|v| violation.set(Some(v))))
  424. .parse("http:////mozilla.org:42").unwrap();
  425. assert_eq!(url.port(), Some(42));
  426. let v = violation.take().unwrap();
  427. assert_eq!(v, ExpectedDoubleSlash);
  428. assert_eq!(v.description(), "expected //");
  429. }
  430. #[test]
  431. fn test_syntax_violation_callback_lifetimes() {
  432. use url::SyntaxViolation::*;
  433. let violation = Cell::new(None);
  434. let vfn = |s| violation.set(Some(s));
  435. let url = Url::options()
  436. .syntax_violation_callback(Some(&vfn))
  437. .parse("http:////mozilla.org:42").unwrap();
  438. assert_eq!(url.port(), Some(42));
  439. assert_eq!(violation.take(), Some(ExpectedDoubleSlash));
  440. let url = Url::options()
  441. .syntax_violation_callback(Some(&vfn))
  442. .parse("http://mozilla.org\\path").unwrap();
  443. assert_eq!(url.path(), "/path");
  444. assert_eq!(violation.take(), Some(Backslash));
  445. }
  446. #[test]
  447. fn test_options_reuse() {
  448. use url::SyntaxViolation::*;
  449. let violations = RefCell::new(Vec::new());
  450. let vfn = |v| violations.borrow_mut().push(v);
  451. let options = Url::options()
  452. .syntax_violation_callback(Some(&vfn));
  453. let url = options.parse("http:////mozilla.org").unwrap();
  454. let options = options.base_url(Some(&url));
  455. let url = options.parse("/sub\\path").unwrap();
  456. assert_eq!(url.as_str(), "http://mozilla.org/sub/path");
  457. assert_eq!(*violations.borrow(),
  458. vec!(ExpectedDoubleSlash, Backslash));
  459. }