@setoelkahfi / svara / commits / cd3bce4

fix: fix sonarcloud issue

apparently control characters shouldnt be in regex

mellbacon committed Oct 8, 2023 at 21:05 UTC cd3bce45b763fc154e7d45747a1214825d6a4903
1 file changed +5 -2
src/lib/File.ts
+5 -2
@@ -252,14 +252,17 @@ export function checkValidFileName(input: string) {
252 // also https://gist.github.com/doctaphred/d01d05291546186941e1b7ddc02034d3
253 const invalidChars = `<>:"|?*${path.sep}`;
254 const invalidKeywords = ["CON", "PRN", "AUX", "NUL", "COM0", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT0", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"];
255 - let nonprintable = new RegExp(/[\x00-\x1F]/); // covers all non printable ascii characters (https://en.wikipedia.org/wiki/Control_character)
255 +
256 + // covers all non printable ascii characters (https://en.wikipedia.org/wiki/Control_character)
257 + for (let i = 0; i < 32; i++) {
258 + if (input.includes(String.fromCharCode(i))) return false;
259 + }
260 for (const c of invalidChars) {
261 if (input.includes(c)) return false;
262 }
263 for (const keyword of invalidKeywords) {
264 if (input.includes(keyword)) return false;
265 }
262 - if (nonprintable.test(input)) return false;
266 if (input.endsWith(".")) return false;
267 if (input === "") return false;
268 return true;