@@ -29,7 +29,7 @@ fn urltestdata() {
2929 "http://GOO\u{200b} \u{2060} \u{feff} goo.com" ,
3030 ] ;
3131
32- // Copied form https://github.com/w3c/ web-platform-tests/blob/master/url/
32+ // Copied from https://github.com/web-platform-tests/wpt /blob/master/url/
3333 let mut json = Value :: from_str ( include_str ! ( "urltestdata.json" ) )
3434 . expect ( "JSON parse error in urltestdata.json" ) ;
3535
@@ -39,7 +39,10 @@ fn urltestdata() {
3939 continue ; // ignore comments
4040 }
4141
42- let base = entry. take_string ( "base" ) ;
42+ let maybe_base = entry
43+ . take_key ( "base" )
44+ . expect ( "missing base key" )
45+ . maybe_string ( ) ;
4346 let input = entry. take_string ( "input" ) ;
4447 let failure = entry. take_key ( "failure" ) . is_some ( ) ;
4548
@@ -50,21 +53,26 @@ fn urltestdata() {
5053 }
5154 }
5255
53- let base = match Url :: parse ( & base) {
54- Ok ( base) => base,
55- Err ( _) if failure => continue ,
56- Err ( message) => {
57- eprint_failure (
58- format ! ( " failed: error parsing base {:?}: {}" , base, message) ,
59- & format ! ( "parse base for {:?}" , input) ,
60- None ,
61- ) ;
62- passed = false ;
63- continue ;
64- }
56+ let res = if let Some ( base) = maybe_base {
57+ let base = match Url :: parse ( & base) {
58+ Ok ( base) => base,
59+ Err ( _) if failure => continue ,
60+ Err ( message) => {
61+ eprint_failure (
62+ format ! ( " failed: error parsing base {:?}: {}" , base, message) ,
63+ & format ! ( "parse base for {:?}" , input) ,
64+ None ,
65+ ) ;
66+ passed = false ;
67+ continue ;
68+ }
69+ } ;
70+ base. join ( & input)
71+ } else {
72+ Url :: parse ( & input)
6573 } ;
6674
67- let url = match ( base . join ( & input ) , failure) {
75+ let url = match ( res , failure) {
6876 ( Ok ( url) , false ) => url,
6977 ( Err ( _) , true ) => continue ,
7078 ( Err ( message) , false ) => {
@@ -180,6 +188,7 @@ fn check_invariants(url: &Url, name: &str, comment: Option<&str>) -> bool {
180188trait JsonExt {
181189 fn take_key ( & mut self , key : & str ) -> Option < Value > ;
182190 fn string ( self ) -> String ;
191+ fn maybe_string ( self ) -> Option < String > ;
183192 fn take_string ( & mut self , key : & str ) -> String ;
184193}
185194
@@ -189,10 +198,14 @@ impl JsonExt for Value {
189198 }
190199
191200 fn string ( self ) -> String {
192- if let Value :: String ( s) = self {
193- s
194- } else {
195- panic ! ( "Not a Value::String" )
201+ self . maybe_string ( ) . expect ( "" )
202+ }
203+
204+ fn maybe_string ( self ) -> Option < String > {
205+ match self {
206+ Value :: String ( s) => Some ( s) ,
207+ Value :: Null => None ,
208+ _ => panic ! ( "Not a Value::String or Value::Null" ) ,
196209 }
197210 }
198211
0 commit comments