Skip to content

Commit 8cb6110

Browse files
committed
boot/categories: Remove line breaks and collapse whitespace in description fields
1 parent 8d3c82b commit 8cb6110

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/boot/categories.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ fn optional_string_from_toml<'a>(toml: &'a toml::value::Table, key: &str) -> &'a
4747
toml.get(key).and_then(toml::Value::as_str).unwrap_or("")
4848
}
4949

50-
fn process_description(description: &str) -> &str {
51-
description.trim()
50+
fn process_description(description: &str) -> String {
51+
description.split_whitespace().collect::<Vec<_>>().join(" ")
5252
}
5353

5454
fn categories_from_toml(
@@ -68,7 +68,7 @@ fn categories_from_toml(
6868
let category = Category::from_parent(
6969
slug,
7070
required_string_from_toml(details, "name")?,
71-
description,
71+
&description,
7272
parent,
7373
);
7474

@@ -152,14 +152,18 @@ mod tests {
152152
"description with spaces"
153153
);
154154

155-
// Preserves internal whitespace
155+
// Collapses internal whitespace
156156
assert_eq!(
157-
process_description(" multi word description "),
157+
process_description(" multi word description "),
158158
"multi word description"
159159
);
160160
assert_eq!(
161161
process_description(" description\nwith\nnewlines "),
162-
"description\nwith\nnewlines"
162+
"description with newlines"
163+
);
164+
assert_eq!(
165+
process_description("text\n\n\nwith\t\tmultiple\n whitespace"),
166+
"text with multiple whitespace"
163167
);
164168

165169
// Empty string

0 commit comments

Comments
 (0)