Revert "Remove illegal chars for Windows on files (#5364)"

This reverts commit 8ed1d35ab3.
This commit is contained in:
Timothy Carambat
2026-04-06 14:03:53 -07:00
parent 5a91608d9e
commit 869be87ef6
4 changed files with 13 additions and 44 deletions

View File

@@ -17,12 +17,7 @@ const { Telemetry } = require("../../models/telemetry");
const { CollectorApi } = require("../collectorApi");
const fs = require("fs");
const path = require("path");
const {
hotdirPath,
normalizePath,
isWithin,
sanitizeFileName,
} = require("../files");
const { hotdirPath, normalizePath, isWithin } = require("../files");
/**
* @typedef ResponseObject
* @property {string} id - uuid of response
@@ -77,8 +72,8 @@ async function processDocumentAttachments(attachments = []) {
if (dataUriMatch) base64Data = dataUriMatch[1];
const buffer = Buffer.from(base64Data, "base64");
const filename = sanitizeFileName(
normalizePath(attachment.name || `attachment-${uuidv4()}`)
const filename = normalizePath(
attachment.name || `attachment-${uuidv4()}`
);
const filePath = normalizePath(path.join(hotdirPath, filename));
if (!isWithin(hotdirPath, filePath))

View File

@@ -284,21 +284,6 @@ function normalizePath(filepath = "") {
return result;
}
/**
* Strips characters that are illegal in Windows filenames, including Unicode
* quotation marks (U+201C, U+201D, etc.) that can get corrupted into ASCII
* double-quotes during charset conversion in the upload pipeline.
* @param {string} fileName - The filename to sanitize.
* @returns {string} - The sanitized filename.
*/
function sanitizeFileName(fileName) {
if (!fileName) return fileName;
return fileName.replace(
/[<>:"/\\|?*\u201C\u201D\u201E\u201F\u2018\u2019\u201A\u201B]/g,
""
);
}
// Check if the vector-cache folder is empty or not
// useful for it the user is changing embedders as this will
// break the previous cache.
@@ -515,5 +500,4 @@ module.exports = {
purgeEntireVectorCache,
getDocumentsByFolder,
hotdirPath,
sanitizeFileName,
};

View File

@@ -2,7 +2,7 @@ const multer = require("multer");
const path = require("path");
const fs = require("fs");
const { v4 } = require("uuid");
const { normalizePath, sanitizeFileName } = require(".");
const { normalizePath } = require(".");
/**
* Handle File uploads for auto-uploading.
@@ -17,8 +17,8 @@ const fileUploadStorage = multer.diskStorage({
cb(null, uploadOutput);
},
filename: function (_, file, cb) {
file.originalname = sanitizeFileName(
normalizePath(Buffer.from(file.originalname, "latin1").toString("utf8"))
file.originalname = normalizePath(
Buffer.from(file.originalname, "latin1").toString("utf8")
);
cb(null, file.originalname);
},
@@ -37,8 +37,8 @@ const fileAPIUploadStorage = multer.diskStorage({
cb(null, uploadOutput);
},
filename: function (_, file, cb) {
file.originalname = sanitizeFileName(
normalizePath(Buffer.from(file.originalname, "latin1").toString("utf8"))
file.originalname = normalizePath(
Buffer.from(file.originalname, "latin1").toString("utf8")
);
cb(null, file.originalname);
},
@@ -55,8 +55,8 @@ const assetUploadStorage = multer.diskStorage({
return cb(null, uploadOutput);
},
filename: function (_, file, cb) {
file.originalname = sanitizeFileName(
normalizePath(Buffer.from(file.originalname, "latin1").toString("utf8"))
file.originalname = normalizePath(
Buffer.from(file.originalname, "latin1").toString("utf8")
);
cb(null, file.originalname);
},