Separate invalid char check for folders and files. Files can't have slashes.

This commit is contained in:
Michael Bucari-Tovo 2022-07-22 18:11:09 -06:00
parent e34ce67a2c
commit 503e1e143e
3 changed files with 7 additions and 5 deletions

View File

@ -168,8 +168,10 @@ namespace FileManager
} }
public static bool ContainsInvalid(string path) public static bool ContainsInvalidPathChar(string path)
=> path.Any(c => invalidChars.Contains(c)); => path.Any(c => invalidChars.Contains(c));
public static bool ContainsInvalidFilenameChar(string path)
=> path.Any(c => invalidChars.Concat(new char[] { '\\', '/' }).Contains(c));
public string ReplaceInvalidFilenameChars(string fileName) public string ReplaceInvalidFilenameChars(string fileName)
{ {
@ -246,7 +248,7 @@ namespace FileManager
dict[3].CharacterToReplace != default3.CharacterToReplace || dict[3].Description != default3.Description || dict[3].CharacterToReplace != default3.CharacterToReplace || dict[3].Description != default3.Description ||
dict[4].CharacterToReplace != default4.CharacterToReplace || dict[4].Description != default4.Description || dict[4].CharacterToReplace != default4.CharacterToReplace || dict[4].Description != default4.Description ||
dict[5].CharacterToReplace != default5.CharacterToReplace || dict[5].Description != default5.Description || dict[5].CharacterToReplace != default5.CharacterToReplace || dict[5].Description != default5.Description ||
dict.Any(r => ReplacementCharacters.ContainsInvalid(r.ReplacementString)) dict.Any(r => ReplacementCharacters.ContainsInvalidPathChar(r.ReplacementString))
) )
{ {
dict = ReplacementCharacters.Default.Replacements; dict = ReplacementCharacters.Default.Replacements;

View File

@ -54,7 +54,7 @@ namespace LibationFileManager
if (template is null) if (template is null)
return new[] { ERROR_NULL_IS_INVALID }; return new[] { ERROR_NULL_IS_INVALID };
if (ReplacementCharacters.ContainsInvalid(template.Replace("<","").Replace(">",""))) if (ReplacementCharacters.ContainsInvalidFilenameChar(template.Replace("<","").Replace(">","")))
return new[] { ERROR_INVALID_FILE_NAME_CHAR }; return new[] { ERROR_INVALID_FILE_NAME_CHAR };
return Valid; return Valid;
@ -201,7 +201,7 @@ namespace LibationFileManager
return new[] { ERROR_FULL_PATH_IS_INVALID }; return new[] { ERROR_FULL_PATH_IS_INVALID };
// must be relative. no colons. all other path chars are valid enough to pass this check and will be handled on final save. // must be relative. no colons. all other path chars are valid enough to pass this check and will be handled on final save.
if (ReplacementCharacters.ContainsInvalid(template.Replace("<", "").Replace(">", ""))) if (ReplacementCharacters.ContainsInvalidPathChar(template.Replace("<", "").Replace(">", "")))
return new[] { ERROR_INVALID_FILE_NAME_CHAR }; return new[] { ERROR_INVALID_FILE_NAME_CHAR };
return Valid; return Valid;

View File

@ -101,7 +101,7 @@ namespace LibationWinForms.Dialogs
{ {
dataGridView1.Rows[e.RowIndex].ErrorText = $"The {charToReplaceStr[0]} character is already being replaced"; dataGridView1.Rows[e.RowIndex].ErrorText = $"The {charToReplaceStr[0]} character is already being replaced";
} }
else if (ReplacementCharacters.ContainsInvalid(replacement)) else if (ReplacementCharacters.ContainsInvalidPathChar(replacement))
{ {
dataGridView1.Rows[e.RowIndex].ErrorText = $"Your {replacementStringCol.HeaderText} contains illegal characters"; dataGridView1.Rows[e.RowIndex].ErrorText = $"Your {replacementStringCol.HeaderText} contains illegal characters";
} }