New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save to file: Allow special characters in file name, e.g. German Umlauts #216
Comments
it was a safety feature for file systems that may break with certain characters, below is the relevant code. The question is - should it be turned off completely risking crashes and Thunderbird hanging if a filter encounters a bad letter and FQ tries to save an illegal file? Or is there another approach - maybe by adding a whitelist of characters you absolutely want to keep? /**
* Removes invalid file name characters
*
* @returns a sanitized name to be used as a filename, or a random name
* if a sanitized name cannot be obtained (if aName contains
* no valid characters).
*/
function _sanitizeName(aName, includesExtension=false) {
const prefs = Services.prefs.getBranch("extensions.filtaquilla.");
let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()_-+'!%" + (includesExtension ? "." : ""),
maxLength = prefs.getIntPref("fileNames.maxLength") || 60;
let spaceChar = fileNamesSpaceCharacter.substring(0,1);
if (!chars.includes(spaceChar)) {
chars += spaceChar;
}
let str = aName; // .toLowerCase();
// diacritics
str = str.replace(/Ä/g, 'Ae');
str = str.replace(/æ|ǽ|ä/g, 'ae');
str = str.replace(/À|Á|Â|Ã|Å|Ǻ|Ā|Ă|Ą|Ǎ|А/g, 'A');
str = str.replace(/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|а/g, 'a');
str = str.replace(/Б/g, 'B');
str = str.replace(/б/g, 'b');
str = str.replace(/Ç|Ć|Ĉ|Ċ|Č|Ц/g, 'C');
str = str.replace(/ç|ć|ĉ|ċ|č|ц/g, 'c');
str = str.replace(/Ð|Ď|Đ/g, 'Dj');
str = str.replace(/ð|ď|đ/g, 'dj');
str = str.replace(/Д/g, 'D');
str = str.replace(/д/g, 'd');
str = str.replace(/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Е|Ё|Э/g, 'E');
str = str.replace(/è|é|ê|ë|ē|ĕ|ė|ę|ě|е|ё|э/g, 'e');
str = str.replace(/Ф/g, 'F');
str = str.replace(/ƒ|ф/g, 'f');
str = str.replace(/Ĝ|Ğ|Ġ|Ģ|Г/g, 'G');
str = str.replace(/ĝ|ğ|ġ|ģ|г/g, 'g');
str = str.replace(/Ĥ|Ħ|Х/g, 'H');
str = str.replace(/ĥ|ħ|х/g, 'h');
str = str.replace(/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|И/g, 'I');
str = str.replace(/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|и/g, 'i');
str = str.replace(/Ĵ|Й/g, 'J');
str = str.replace(/ĵ|й/g, 'j');
str = str.replace(/Ķ|К/g, 'K');
str = str.replace(/ķ|к/g, 'k');
str = str.replace(/Ĺ|Ļ|Ľ|Ŀ|Ł|Л/g, 'L');
str = str.replace(/ĺ|ļ|ľ|ŀ|ł|л/g, 'l');
str = str.replace(/М/g, 'M');
str = str.replace(/м/g, 'm');
str = str.replace(/Ñ|Ń|Ņ|Ň|Н/g, 'N');
str = str.replace(/ñ|ń|ņ|ň|ʼn|н/g, 'n');
str = str.replace(/Ö/g, 'Oe');
str = str.replace(/œ|ö/g, 'oe');
str = str.replace(/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|О/g, 'O');
str = str.replace(/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|о/g, 'o');
str = str.replace(/П/g, 'P');
str = str.replace(/п/g, 'p');
str = str.replace(/Ŕ|Ŗ|Ř|Р/g, 'R');
str = str.replace(/ŕ|ŗ|ř|р/g, 'r');
str = str.replace(/Ś|Ŝ|Ş|Ș|Š|С/g, 'S');
str = str.replace(/ś|ŝ|ş|ș|š|ſ|с/g, 's');
str = str.replace(/Ţ|Ț|Ť|Ŧ|Т/g, 'T');
str = str.replace(/ţ|ț|ť|ŧ|т/g, 't');
str = str.replace(/Ü/g, 'Ue');
str = str.replace(/ü/g, 'ue');
str = str.replace(/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|У/g, 'U');
str = str.replace(/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|у/g, 'u');
str = str.replace(/В/g, 'V');
str = str.replace(/в/g, 'v');
str = str.replace(/Ý|Ÿ|Ŷ|Ы/g, 'Y');
str = str.replace(/ý|ÿ|ŷ|ы/g, 'y');
str = str.replace(/Ŵ/g, 'W');
str = str.replace(/ŵ/g, 'w');
str = str.replace(/Ź|Ż|Ž|З/g, 'Z');
str = str.replace(/ź|ż|ž|з/g, 'z');
str = str.replace(/Æ|Ǽ/g, 'AE');
str = str.replace(/ß/g, 'ss');
str = str.replace(/IJ/g, 'IJ');
str = str.replace(/ij/g, 'ij');
str = str.replace(/Œ/g, 'OE');
str = str.replace(/Ч/g, 'Ch');
str = str.replace(/ч/g, 'ch');
str = str.replace(/Ю/g, 'Ju');
str = str.replace(/ю/g, 'ju');
str = str.replace(/Я/g, 'Ja');
str = str.replace(/я/g, 'ja');
str = str.replace(/Ш/g, 'Sh');
str = str.replace(/ш/g, 'sh');
str = str.replace(/Щ/g, 'Shch');
str = str.replace(/щ/g, 'shch');
str = str.replace(/Ж/g, 'Zh');
str = str.replace(/ж/g, 'zh');
str = str.replace("&","+"); // improve readability
// special characters
let name = str.trim().replace(/ /g, spaceChar); // used to be "-"
name = name.replace(/[@:\|\/\\\*\?]/g, "-");
name = name.replace(/[\$"<>,]/g, "").trim();
name = name.split("").filter(function (el) {
return chars.indexOf(el) != -1;
}).join("");
if (!name) {
// Our input had no valid characters - use a random name
let cl = chars.length - 1;
for (let i = 0; i < 8; ++i)
name += chars.charAt(Math.round(Math.random() * cl));
}
if (name.length > maxLength) {
let ext;
if (includesExtension) {
let i = name.lastIndexOf(".");
if (i>0) {
ext = name.substr(i);
}
}
if (ext) {
name = name.substring(0, maxLength-ext.length) + ext;
}
else {
name = name.substring(0, maxLength);
}
}
return name;
} |
I think turning off security for filesystems that can't handle certain characters in general isn't a good idea. Otherwise I can live with the "problem". There is only one month with an umlaut in German. |
Well a whitelist would only be useful if there was a way to add it via the FiltaQuilla Preference dialog... I would just need to rework the replacing code with a map and then remove the whitelisted characters in real time. |
That would of course be a perfect solution! |
Here is a trial version that implements the white list feature. All allowed letters can be added to the whitelist string (no delimiters needed) I am storing the setting in the new config setting But I added the UI for it right here: To try out, download the zip file and drag it into Thunderbird Add-ons Manager to install it. |
PS: the screenshot of the preferences in about:config is from Thunderbird Settings / General / [Config Editor...] (bottom right) |
no sorry I tested again, it works for me... strange one. |
Can you add all Umlauts |
Now it works perfect. |
Just for the sake of completeness: While your list covers the lowercase sharp s <ß>, it's missing the (admittedly rarely used) uppercase sharp s <ẞ>, which should be replaced by <SS>. |
yes will do. never knew there was such a thing - back in the day I learned from a friend who worked in typesetting before that you never ever are allowed to is the sharp s in an uppercase heading on account of It looking too much like an uppercase B. the more you know! |
Use Filtquilla for a long time. For me it is the best.
My problem
When using "save to file" it saves the files (examples)
Bericht Altes Forsthaus - Woche 27. Februar - 5. März 2023.pdf
Bericht Alle Websites - Freitag 17. März 2023.pdf
as
Bericht Altes Forsthaus - Woche 27. Februar - 5. Maerz 2023.pdf
Bericht Alle Websites - Freitag 17. Maerz 2023.pdf
and change "ä" to "ae"
Can you please fix it?
The text was updated successfully, but these errors were encountered: