fix: Document title with slashes produces folders in exported zip file
closes #2036
This commit is contained in:
@ -11,6 +11,7 @@ import parseTitle from "../../shared/utils/parseTitle";
|
||||
import { FileImportError, InvalidRequestError } from "../errors";
|
||||
import { User } from "../models";
|
||||
import dataURItoBuffer from "../utils/dataURItoBuffer";
|
||||
import { deserializeFilename } from "../utils/fs";
|
||||
import parseImages from "../utils/parseImages";
|
||||
import attachmentCreator from "./attachmentCreator";
|
||||
|
||||
@ -152,7 +153,7 @@ export default async function documentImporter({
|
||||
if (!fileInfo) {
|
||||
throw new InvalidRequestError(`File type ${file.type} not supported`);
|
||||
}
|
||||
let title = file.name.replace(/\.[^/.]+$/, "");
|
||||
let title = deserializeFilename(file.name.replace(/\.[^/.]+$/, ""));
|
||||
let text = await fileInfo.getMarkdown(file);
|
||||
|
||||
// If the first line of the imported text looks like a markdown heading
|
||||
|
@ -94,6 +94,25 @@ describe("documentImporter", () => {
|
||||
expect(response.title).toEqual("Heading 1");
|
||||
});
|
||||
|
||||
it("should handle encoded slashes", async () => {
|
||||
const user = await buildUser();
|
||||
const name = "this %2F and %2F this.md";
|
||||
const file = new File({
|
||||
name,
|
||||
type: "text/plain",
|
||||
path: path.resolve(__dirname, "..", "test", "fixtures", "empty.md"),
|
||||
});
|
||||
|
||||
const response = await documentImporter({
|
||||
user,
|
||||
file,
|
||||
ip,
|
||||
});
|
||||
|
||||
expect(response.text).toContain("");
|
||||
expect(response.title).toEqual("this / and / this");
|
||||
});
|
||||
|
||||
it("should fallback to extension if mimetype unknown", async () => {
|
||||
const user = await buildUser();
|
||||
const name = "markdown.md";
|
||||
|
Reference in New Issue
Block a user