Skip to content

Commit 0a87dfc

Browse files
fix: handle quoted directives in Cache-Control header (#216)
* Cache-control parsing doesn't handle quotes * Group quoted blocks in csv::from_comma_delimited
1 parent 8db1b78 commit 0a87dfc

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/common/cache_control.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,15 @@ mod tests {
485485
);
486486
}
487487

488+
#[test]
489+
fn test_parse_quoted_comma() {
490+
assert_eq!(
491+
test_decode::<CacheControl>(&["foo=\"a, private, immutable, b\", no-cache"]).unwrap(),
492+
CacheControl::new().with_no_cache(),
493+
"unknown extensions are ignored but shouldn't fail parsing",
494+
)
495+
}
496+
488497
#[test]
489498
fn test_parse_extension() {
490499
assert_eq!(

src/util/csv.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,26 @@ where
1414
values
1515
.flat_map(|value| {
1616
value.to_str().into_iter().flat_map(|string| {
17+
let mut in_quotes = false;
1718
string
18-
.split(',')
19+
.split(move |c| {
20+
#[allow(clippy::collapsible_else_if)]
21+
if in_quotes {
22+
if c == '"' {
23+
in_quotes = false;
24+
}
25+
false // dont split
26+
} else {
27+
if c == ',' {
28+
true // split
29+
} else {
30+
if c == '"' {
31+
in_quotes = true;
32+
}
33+
false // dont split
34+
}
35+
}
36+
})
1937
.filter_map(|x| match x.trim() {
2038
"" => None,
2139
y => Some(y),

0 commit comments

Comments
 (0)