Fixing issue #353 Forward Slash in site or channel name causes recording error (#448)

* Fixing issue #353
Moved replaceIllegalCharacters method into StringUtils.
Modified classes that write out to disk to call this method when saving a file.

* Implementing suggested changes from comments in PR #448
This commit is contained in:
whelgeson
2018-12-16 18:10:56 -06:00
committed by Denny Sheirer
parent 4a4d1d4b2e
commit 72fe72c833
6 changed files with 27 additions and 28 deletions

View File

@@ -20,6 +20,9 @@ package io.github.dsheirer.util;
public class StringUtils
{
private static final String[] ILLEGAL_FILENAME_CHARACTERS = {"#", "%", "&", "{", "}", "\\", "<", ">",
"*", "?", "/", " ", "$", "!", "'", "\"", ":", "@", "+", "`", "|", "="};
/**
* Compares string a to b and returns true if a is non-null and non-empty, b is non-null and non-empty, and
* a is equal to b.
@@ -38,4 +41,15 @@ public class StringUtils
{
return a == null || a.isEmpty();
}
/**
* Replaces any illegal filename characters in the proposed filename
*/
public static String replaceIllegalCharacters(String filename) {
for (String illegalCharacter : ILLEGAL_FILENAME_CHARACTERS) {
filename = filename.replace(illegalCharacter, "_");
}
return filename;
}
}