@@ -30,7 +30,7 @@ fn urltestdata() {
30
30
"http://GOO\u{200b} \u{2060} \u{feff} goo.com" ,
31
31
] ;
32
32
33
- // Copied form https://github.com/w3c/ web-platform-tests/blob/master/url/
33
+ // Copied from https://github.com/web-platform-tests/wpt /blob/master/url/
34
34
let mut json = Value :: from_str ( include_str ! ( "urltestdata.json" ) )
35
35
. expect ( "JSON parse error in urltestdata.json" ) ;
36
36
@@ -40,7 +40,10 @@ fn urltestdata() {
40
40
continue ; // ignore comments
41
41
}
42
42
43
- let base = entry. take_string ( "base" ) ;
43
+ let maybe_base = entry
44
+ . take_key ( "base" )
45
+ . expect ( "missing base key" )
46
+ . maybe_string ( ) ;
44
47
let input = entry. take_string ( "input" ) ;
45
48
let failure = entry. take_key ( "failure" ) . is_some ( ) ;
46
49
@@ -51,21 +54,26 @@ fn urltestdata() {
51
54
}
52
55
}
53
56
54
- let base = match Url :: parse ( & base) {
55
- Ok ( base) => base,
56
- Err ( _) if failure => continue ,
57
- Err ( message) => {
58
- eprint_failure (
59
- format ! ( " failed: error parsing base {:?}: {}" , base, message) ,
60
- & format ! ( "parse base for {:?}" , input) ,
61
- None ,
62
- ) ;
63
- passed = false ;
64
- continue ;
65
- }
57
+ let res = if let Some ( base) = maybe_base {
58
+ let base = match Url :: parse ( & base) {
59
+ Ok ( base) => base,
60
+ Err ( _) if failure => continue ,
61
+ Err ( message) => {
62
+ eprint_failure (
63
+ format ! ( " failed: error parsing base {:?}: {}" , base, message) ,
64
+ & format ! ( "parse base for {:?}" , input) ,
65
+ None ,
66
+ ) ;
67
+ passed = false ;
68
+ continue ;
69
+ }
70
+ } ;
71
+ base. join ( & input)
72
+ } else {
73
+ Url :: parse ( & input)
66
74
} ;
67
75
68
- let url = match ( base . join ( & input ) , failure) {
76
+ let url = match ( res , failure) {
69
77
( Ok ( url) , false ) => url,
70
78
( Err ( _) , true ) => continue ,
71
79
( Err ( message) , false ) => {
@@ -182,6 +190,7 @@ fn check_invariants(url: &Url, name: &str, comment: Option<&str>) -> bool {
182
190
trait JsonExt {
183
191
fn take_key ( & mut self , key : & str ) -> Option < Value > ;
184
192
fn string ( self ) -> String ;
193
+ fn maybe_string ( self ) -> Option < String > ;
185
194
fn take_string ( & mut self , key : & str ) -> String ;
186
195
}
187
196
@@ -191,10 +200,14 @@ impl JsonExt for Value {
191
200
}
192
201
193
202
fn string ( self ) -> String {
194
- if let Value :: String ( s) = self {
195
- s
196
- } else {
197
- panic ! ( "Not a Value::String" )
203
+ self . maybe_string ( ) . expect ( "" )
204
+ }
205
+
206
+ fn maybe_string ( self ) -> Option < String > {
207
+ match self {
208
+ Value :: String ( s) => Some ( s) ,
209
+ Value :: Null => None ,
210
+ _ => panic ! ( "Not a Value::String or Value::Null" ) ,
198
211
}
199
212
}
200
213
0 commit comments