Skip to content

Commit bd43f7a

Browse files
Group quoted blocks in csv::from_comma_delimited
1 parent 6a923d6 commit bd43f7a

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/common/cache_control.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,7 @@ mod tests {
489489
fn test_parse_quoted_comma() {
490490
assert_eq!(
491491
test_decode::<CacheControl>(&["foo=\"a, private, immutable, b\", no-cache"]).unwrap(),
492-
CacheControl::new()
493-
.with_no_cache()
494-
// These are wrong: these appear inside a quoted string and so
495-
// should be treated as parameter for the "a" directive.
496-
.with_private()
497-
.with_immutable(),
492+
CacheControl::new().with_no_cache(),
498493
"unknown extensions are ignored but shouldn't fail parsing",
499494
)
500495
}

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)