Skip to content
Snippets Groups Projects
Unverified Commit fa4ab0f6 authored by Jason Zhang's avatar Jason Zhang Committed by GitHub
Browse files

fix: sanitize filename before writing (#1743)

* fix: sanitize filename before writing

Fixes: https://github.com/Mintplex-Labs/anything-llm/issues/1737

* fixup

* fixup
parent dde8bc23
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ const path = require("path"); ...@@ -3,7 +3,7 @@ const path = require("path");
const { default: slugify } = require("slugify"); const { default: slugify } = require("slugify");
const { v4 } = require("uuid"); const { v4 } = require("uuid");
const UrlPattern = require("url-pattern"); const UrlPattern = require("url-pattern");
const { writeToServerDocuments } = require("../../files"); const { writeToServerDocuments, sanitizeFileName } = require("../../files");
const { tokenizeString } = require("../../tokenizer"); const { tokenizeString } = require("../../tokenizer");
const { const {
ConfluencePagesLoader, ConfluencePagesLoader,
...@@ -98,11 +98,11 @@ async function loadConfluence({ pageUrl, username, accessToken }, response) { ...@@ -98,11 +98,11 @@ async function loadConfluence({ pageUrl, username, accessToken }, response) {
console.log( console.log(
`[Confluence Loader]: Saving ${doc.metadata.title} to ${outFolder}` `[Confluence Loader]: Saving ${doc.metadata.title} to ${outFolder}`
); );
writeToServerDocuments(
data, const fileName = sanitizeFileName(
`${slugify(doc.metadata.title)}-${data.id}`, `${slugify(doc.metadata.title)}-${data.id}`
outFolderPath
); );
writeToServerDocuments(data, fileName, outFolderPath);
}); });
return { return {
......
...@@ -129,6 +129,11 @@ function normalizePath(filepath = "") { ...@@ -129,6 +129,11 @@ function normalizePath(filepath = "") {
return result; return result;
} }
function sanitizeFileName(fileName) {
if (!fileName) return fileName;
return fileName.replace(/[<>:"\/\\|?*]/g, "");
}
module.exports = { module.exports = {
trashFile, trashFile,
isTextType, isTextType,
...@@ -137,4 +142,5 @@ module.exports = { ...@@ -137,4 +142,5 @@ module.exports = {
wipeCollectorStorage, wipeCollectorStorage,
normalizePath, normalizePath,
isWithin, isWithin,
sanitizeFileName,
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment