From cf370bfdda4bd2630972354114db54a0c31490bf Mon Sep 17 00:00:00 2001 From: Hunter Kehoe Date: Tue, 18 Oct 2022 22:02:04 -0600 Subject: [PATCH] strip trailing slash after server url in publish dialog fixes #441 --- web/src/components/PublishDialog.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/web/src/components/PublishDialog.js b/web/src/components/PublishDialog.js index 13108239..99db9af2 100644 --- a/web/src/components/PublishDialog.js +++ b/web/src/components/PublishDialog.js @@ -90,6 +90,14 @@ const PublishDialog = (props) => { setMessage(props.message); }, [props.message]); + const updateBaseUrl = (newVal) => { + if (validUrl(newVal)) { + setBaseUrl(newVal.replace(/\/$/, '')); // strip traililng slash after https?:// + } else { + setBaseUrl(newVal); + } + }; + const handleSubmit = async () => { const url = new URL(topicUrl(baseUrl, topic)); if (title.trim()) { @@ -242,7 +250,7 @@ const PublishDialog = (props) => { label={t("publish_dialog_base_url_label")} placeholder={t("publish_dialog_base_url_placeholder")} value={baseUrl} - onChange={ev => setBaseUrl(ev.target.value)} + onChange={ev => updateBaseUrl(ev.target.value)} disabled={disabled} type="url" variant="standard"