@@ -29,7 +29,7 @@ fn urltestdata() {
29
29
"http://GOO\u{200b} \u{2060} \u{feff} goo.com" ,
30
30
] ;
31
31
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/
33
33
let mut json = Value :: from_str ( include_str ! ( "urltestdata.json" ) )
34
34
. expect ( "JSON parse error in urltestdata.json" ) ;
35
35
@@ -39,7 +39,10 @@ fn urltestdata() {
39
39
continue ; // ignore comments
40
40
}
41
41
42
- let base = entry. take_string ( "base" ) ;
42
+ let maybe_base = entry
43
+ . take_key ( "base" )
44
+ . expect ( "missing base key" )
45
+ . maybe_string ( ) ;
43
46
let input = entry. take_string ( "input" ) ;
44
47
let failure = entry. take_key ( "failure" ) . is_some ( ) ;
45
48
@@ -50,21 +53,26 @@ fn urltestdata() {
50
53
}
51
54
}
52
55
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)
65
73
} ;
66
74
67
- let url = match ( base . join ( & input ) , failure) {
75
+ let url = match ( res , failure) {
68
76
( Ok ( url) , false ) => url,
69
77
( Err ( _) , true ) => continue ,
70
78
( Err ( message) , false ) => {
@@ -180,6 +188,7 @@ fn check_invariants(url: &Url, name: &str, comment: Option<&str>) -> bool {
180
188
trait JsonExt {
181
189
fn take_key ( & mut self , key : & str ) -> Option < Value > ;
182
190
fn string ( self ) -> String ;
191
+ fn maybe_string ( self ) -> Option < String > ;
183
192
fn take_string ( & mut self , key : & str ) -> String ;
184
193
}
185
194
@@ -189,10 +198,14 @@ impl JsonExt for Value {
189
198
}
190
199
191
200
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" ) ,
196
209
}
197
210
}
198
211
0 commit comments