Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
upload: Name the link based on the uploaded filename.
Alex Vandiver8bd94b82bf48
diff --git a/web/src/upload.ts b/web/src/upload.tsindex 8dec24540ef..c91f2f35075 100644--- a/web/src/upload.ts+++ b/web/src/upload.ts@@ -372,10 +372,13 @@ export function setup_upload(config: Config): Uppy {uppy.on("upload-success", (file, response) => {assert(file !== undefined);- const {url} = z.object({url: z.string()}).parse(response.body);- const split_url = url.split("/");- const filename = split_url.at(-1);- const syntax_to_insert = "[" + filename + "](" + url + ")";+ const {url, filename} = z+ .object({url: z.string(), filename: z.string()})+ .parse(response.body);+ // Our markdown does not have escape characters, so we cannot link any text with brackets;+ // strip them out, if present.+ const filtered_filename = filename.replaceAll("[", "").replaceAll("]", "");+ const syntax_to_insert = "[" + filtered_filename + "](" + url + ")";const $text_area = config.textarea();const replacement_successful = compose_ui.replace_syntax(get_translated_status(file),diff --git a/web/tests/upload.test.js b/web/tests/upload.test.jsindex 6d6f02c91e9..4d9ea5ee320 100644--- a/web/tests/upload.test.js+++ b/web/tests/upload.test.js@@ -501,6 +501,7 @@ test("uppy_events", ({override_rewire, mock_template}) => {let response = {body: {url: "/user_uploads/4/cb/rue1c-MlMUjDAUdkRrEM4BTJ/copenhagen.png",+ filename: "copenhagen.png",},};