catch trailing space/period as well
This commit is contained in:
parent
5ccdeb46b8
commit
58da7988c3
@ -37,6 +37,16 @@ lazy_static! {
|
||||
"#
|
||||
)
|
||||
.unwrap();
|
||||
static ref WINDOWS_TRAILING_CHAR: Regex = Regex::new(
|
||||
r#"(?x)
|
||||
# filenames can't end with a space or period
|
||||
(
|
||||
\x20 | \.
|
||||
)
|
||||
$
|
||||
"#
|
||||
)
|
||||
.unwrap();
|
||||
pub(super) static ref NONSYNCABLE_FILENAME: Regex = Regex::new(
|
||||
r#"(?xi)
|
||||
^
|
||||
@ -84,6 +94,10 @@ fn normalize_nfc_filename(mut fname: Cow<str>) -> Cow<str> {
|
||||
fname = o.into();
|
||||
}
|
||||
|
||||
if WINDOWS_TRAILING_CHAR.is_match(fname.as_ref()) {
|
||||
fname = format!("{}_", fname.as_ref()).into();
|
||||
}
|
||||
|
||||
if let Cow::Owned(o) = truncate_filename(fname.as_ref(), MAX_FILENAME_LENGTH) {
|
||||
fname = o.into();
|
||||
}
|
||||
@ -393,6 +407,9 @@ mod test {
|
||||
"con_.jpg"
|
||||
);
|
||||
|
||||
assert_eq!(normalize_filename("test.").as_ref(), "test._");
|
||||
assert_eq!(normalize_filename("test ").as_ref(), "test _");
|
||||
|
||||
let expected_stem_len = MAX_FILENAME_LENGTH - ".jpg".len();
|
||||
assert_eq!(
|
||||
normalize_filename(&format!("{}.jpg", "x".repeat(MAX_FILENAME_LENGTH * 2))),
|
||||
|
Loading…
Reference in New Issue
Block a user