Skip to content

Commit edbe668

Browse files
committed
fixup! ACME: alternative chains support.
1 parent e51e0e7 commit edbe668

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/acme/headers.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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('"')?));
@@ -115,11 +123,16 @@ impl<'a> Iterator for LinkIter<'a> {
115123
}
116124
}
117125

118-
None
126+
Some((p, ""))
119127
}
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,10 +200,24 @@ 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",
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+
],
212+
),
213+
(
214+
"<https://example.com/acme/directory>;rel=\"index",
192215
&[("https://example.com/acme/directory", &["index"])],
193216
),
217+
(
218+
r#"<https://example.com/acme/directory>;rel="index\""#,
219+
&[("https://example.com/acme/directory", &["index\\\""])],
220+
),
194221
(
195222
// multiple link-values
196223
concat!(

0 commit comments

Comments
 (0)