From afc0df74839243961b3c9729d453990ad274b3d9 Mon Sep 17 00:00:00 2001 From: Erez Rokah Date: Mon, 26 Jul 2021 14:35:47 +0200 Subject: [PATCH] fix: remove identity prefix from site URL if exists (#482) --- src/components/forms/siteurl.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/forms/siteurl.js b/src/components/forms/siteurl.js index f7a4e3d99..b3636c2d2 100644 --- a/src/components/forms/siteurl.js +++ b/src/components/forms/siteurl.js @@ -1,5 +1,18 @@ import { h, Component } from "preact"; +/** + * @arg {string} string + * @arg {string} ending + **/ +function removeFrom(string, mark) { + const index = string.indexOf(mark); + if (index === -1) { + return string; + } + + return string.substring(0, string.length - mark.length); +} + export default class SiteURLForm extends Component { constructor(props) { super(props); @@ -12,7 +25,8 @@ export default class SiteURLForm extends Component { addSiteURL = (e) => { e.preventDefault(); - this.props.onSiteURL(this.state.url); + const url = removeFrom(this.state.url, "/.netlify/identity"); + this.props.onSiteURL(url); }; clearSiteURL = (e) => {