@@ -35,6 +35,8 @@ impl<'a> Iterator for LinkIter<'a> {
3535 type Item = Link < ' a > ;
3636
3737 fn next ( & mut self ) -> Option < Self :: Item > {
38+ // Link = [ ( "," / link-value ) *( OWS "," [ OWS link-value ] ) ]
39+
3840 // link-value = "<" URI-Reference ">" *( OWS ";" OWS link-param )
3941 fn consume_link_value ( p : & str ) -> Option < ( Link < ' _ > , & str ) > {
4042 let p = p. trim_ascii_start ( ) . strip_prefix ( '<' ) ?;
@@ -65,6 +67,12 @@ impl<'a> Iterator for LinkIter<'a> {
6567 let value;
6668 ( name, value, p) = consume_link_param ( p) ?;
6769
70+ // 9. Let relations_string be the second item of the first tuple
71+ // of link_parameters whose first item matches the string "rel"
72+ // or the empty string ("") if it is not present.
73+ // 10. Split relations_string on RWS (removing it in the process)
74+ // into a list of string relation_types.
75+
6876 if rel. is_empty ( ) && name. eq_ignore_ascii_case ( "rel" ) {
6977 rel. extend ( value. split_ascii_whitespace ( ) ) ;
7078 }
@@ -106,7 +114,7 @@ impl<'a> Iterator for LinkIter<'a> {
106114
107115 for ( i, c) in p. char_indices ( ) {
108116 if c == '\\' {
109- escape = true ;
117+ escape = !escape ;
110118 } else if c == '"' && !escape {
111119 let ( head, tail) = p. split_at ( i) ;
112120 return Some ( ( head, tail. strip_prefix ( '"' ) ?) ) ;
@@ -120,6 +128,11 @@ impl<'a> Iterator for LinkIter<'a> {
120128
121129 let link;
122130
131+ self . 0 = self . 0 . trim_ascii_start ( ) ;
132+ while let Some ( p) = self . 0 . strip_prefix ( ',' ) {
133+ self . 0 = p. trim_ascii_start ( ) ;
134+ }
135+
123136 ( link, self . 0 ) = consume_link_value ( self . 0 ) ?;
124137
125138 Some ( link)
@@ -187,9 +200,15 @@ mod tests {
187200 & [ ( "test" , & [ "alternate" ] ) ] ,
188201 ) ,
189202 (
190- // spaces and other parser sanity checks
191- " <https://example.com/acme/directory> ;\t foo=\" ;,=<>\" ; rel = \" index\" \t " ,
192- & [ ( "https://example.com/acme/directory" , & [ "index" ] ) ] ,
203+ // spaces, commas and other parser sanity checks
204+ concat ! (
205+ " , <https://example.com/acme/directory> ;\t foo=\" ;,=<>\" ; rel = \" index\" \t , ,,, " ,
206+ " , <https://example.com/acme/directory> ;\t foo=\" ;,=<>\" ; rel = \" index\" \t , ,,, "
207+ ) ,
208+ & [
209+ ( "https://example.com/acme/directory" , & [ "index" ] ) ,
210+ ( "https://example.com/acme/directory" , & [ "index" ] )
211+ ] ,
193212 ) ,
194213 (
195214 // multiple link-values
0 commit comments