From 17d260f3aece2f4221e8ffd438d8b10d24366008 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 14 Oct 2019 17:26:54 +1300 Subject: [PATCH 1/2] Check that url is defined before passing into prependHttp --- packages/format-library/src/link/inline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/format-library/src/link/inline.js b/packages/format-library/src/link/inline.js index bf1784db2132d..37200456b2e84 100644 --- a/packages/format-library/src/link/inline.js +++ b/packages/format-library/src/link/inline.js @@ -227,7 +227,7 @@ class InlineLinkUI extends Component { onKeyPress={ stopKeyPropagation } url={ url } onEditLinkClick={ this.editLink } - linkClassName={ isValidHref( prependHTTP( url ) ) ? undefined : 'has-invalid-link' } + linkClassName={ url && isValidHref( prependHTTP( url ) ) ? undefined : 'has-invalid-link' } /> ) } From c82630b2307da6fd80ce1f49fb8884807b5e0d44 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 16 Oct 2019 13:23:37 +1300 Subject: [PATCH 2/2] Shift check from component to url lib --- packages/format-library/src/link/inline.js | 2 +- packages/url/src/index.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/format-library/src/link/inline.js b/packages/format-library/src/link/inline.js index 37200456b2e84..bf1784db2132d 100644 --- a/packages/format-library/src/link/inline.js +++ b/packages/format-library/src/link/inline.js @@ -227,7 +227,7 @@ class InlineLinkUI extends Component { onKeyPress={ stopKeyPropagation } url={ url } onEditLinkClick={ this.editLink } - linkClassName={ url && isValidHref( prependHTTP( url ) ) ? undefined : 'has-invalid-link' } + linkClassName={ isValidHref( prependHTTP( url ) ) ? undefined : 'has-invalid-link' } /> ) } diff --git a/packages/url/src/index.js b/packages/url/src/index.js index b4fa34efac51a..2b549d6ba1dc4 100644 --- a/packages/url/src/index.js +++ b/packages/url/src/index.js @@ -360,6 +360,10 @@ export function removeQueryArgs( url, ...args ) { * @return {string} The updated URL. */ export function prependHTTP( url ) { + if ( ! url ) { + return url; + } + url = url.trim(); if ( ! USABLE_HREF_REGEXP.test( url ) && ! EMAIL_REGEXP.test( url ) ) { return 'http://' + url;