Skip to content

Commit

Permalink
fix: sanitize filename before writing (Mintplex-Labs#1743)
Browse files Browse the repository at this point in the history
* fix: sanitize filename before writing

Fixes: Mintplex-Labs#1737

* fixup

* fixup
  • Loading branch information
jazelly authored and TuanBC committed Aug 26, 2024
1 parent ff6b41a commit 1f222d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions collector/utils/extensions/Confluence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require("path");
const { default: slugify } = require("slugify");
const { v4 } = require("uuid");
const UrlPattern = require("url-pattern");
const { writeToServerDocuments } = require("../../files");
const { writeToServerDocuments, sanitizeFileName } = require("../../files");
const { tokenizeString } = require("../../tokenizer");
const {
ConfluencePagesLoader,
Expand Down Expand Up @@ -98,11 +98,11 @@ async function loadConfluence({ pageUrl, username, accessToken }, response) {
console.log(
`[Confluence Loader]: Saving ${doc.metadata.title} to ${outFolder}`
);
writeToServerDocuments(
data,
`${slugify(doc.metadata.title)}-${data.id}`,
outFolderPath

const fileName = sanitizeFileName(
`${slugify(doc.metadata.title)}-${data.id}`
);
writeToServerDocuments(data, fileName, outFolderPath);
});

return {
Expand Down
6 changes: 6 additions & 0 deletions collector/utils/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ function normalizePath(filepath = "") {
return result;
}

function sanitizeFileName(fileName) {
if (!fileName) return fileName;
return fileName.replace(/[<>:"\/\\|?*]/g, "");
}

module.exports = {
trashFile,
isTextType,
Expand All @@ -137,4 +142,5 @@ module.exports = {
wipeCollectorStorage,
normalizePath,
isWithin,
sanitizeFileName,
};

0 comments on commit 1f222d9

Please sign in to comment.