Skip to content

Commit

Permalink
Skip extracting whitespace-only messages
Browse files Browse the repository at this point in the history
This skips empty messages and messages consisting of whitespace only.

Fixes #64.
  • Loading branch information
mgeisler committed Nov 5, 2023
1 parent a551c69 commit 2c3f2ee
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion i18n-helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,10 @@ pub fn extract_messages(document: &str) -> Vec<(usize, String)> {
Group::Translate(events) => {
if let Some((lineno, _)) = events.first() {
let (text, new_state) = reconstruct_markdown(events, state);
messages.push((*lineno, text));
if !text.trim().is_empty() {
// Skip empty messages.
messages.push((*lineno, text));
}
state = Some(new_state);
}
}
Expand Down Expand Up @@ -689,6 +692,16 @@ mod tests {
assert_extract_messages("", vec![]);
}

#[test]
fn extract_messages_empty_html() {
assert_extract_messages("<span></span>", vec![]);
}

#[test]
fn extract_messages_whitespace_only() {
assert_extract_messages("<span> </span>", vec![]);
}

#[test]
fn extract_messages_single_line() {
assert_extract_messages("This is a paragraph.", vec![(1, "This is a paragraph.")]);
Expand Down

0 comments on commit 2c3f2ee

Please sign in to comment.