diff --git a/rslib/src/media/files.rs b/rslib/src/media/files.rs index 763cdb47c..0ef45a7af 100644 --- a/rslib/src/media/files.rs +++ b/rslib/src/media/files.rs @@ -67,6 +67,10 @@ fn disallowed_char(char: char) -> bool { } } +fn nonbreaking_space(char: char) -> bool { + char == '\u{a0}' +} + /// Adjust filename into the format Anki expects. /// /// - The filename is normalized to NFC. @@ -85,10 +89,16 @@ pub(crate) fn normalize_filename(fname: &str) -> Cow { /// See normalize_filename(). This function expects NFC-normalized input. pub(crate) fn normalize_nfc_filename(mut fname: Cow) -> Cow { - if fname.chars().any(disallowed_char) { + if fname.contains(disallowed_char) { fname = fname.replace(disallowed_char, "").into() } + // convert nonbreaking spaces to regular ones, as the filename extraction + // code treats nonbreaking spaces as regular ones + if fname.contains(nonbreaking_space) { + fname = fname.replace(nonbreaking_space, " ").into() + } + if let Cow::Owned(o) = WINDOWS_DEVICE_NAME.replace_all(fname.as_ref(), "${1}_${2}") { fname = o.into(); } diff --git a/rslib/src/text.rs b/rslib/src/text.rs index 57845615e..17cf98ec7 100644 --- a/rslib/src/text.rs +++ b/rslib/src/text.rs @@ -95,7 +95,7 @@ pub fn strip_html_preserving_entities(html: &str) -> Cow { pub fn decode_entities(html: &str) -> Cow { if html.contains('&') { match htmlescape::decode_html(html) { - Ok(text) => text.replace("\u{a0}", " "), + Ok(text) => text.replace('\u{a0}', " "), Err(e) => format!("{:?}", e), } .into()