From 973657d8a42fe071f6e1c228c560a690cd71d78c Mon Sep 17 00:00:00 2001 From: bluefuton Date: Tue, 24 Nov 2015 11:47:04 +0000 Subject: [PATCH 1/3] Following Management: check for a valid-looking .tld before activating feed input --- client/reader/following-edit/subscribe-form.jsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/client/reader/following-edit/subscribe-form.jsx b/client/reader/following-edit/subscribe-form.jsx index 6039512223193..19c487cdab9a8 100644 --- a/client/reader/following-edit/subscribe-form.jsx +++ b/client/reader/following-edit/subscribe-form.jsx @@ -3,7 +3,8 @@ // External dependencies const React = require( 'react' ), url = require( 'url' ), - noop = require( 'lodash/utility/noop' ); + noop = require( 'lodash/utility/noop' ), + last = require( 'lodash/array/last' ); // Internal dependencies const Search = require( 'components/search' ), @@ -56,7 +57,7 @@ var FollowingEditSubscribeForm = React.createClass( { handleKeyDown: function( event ) { // Use Enter to submit - if ( event.keyCode === 13 && this.state.searchString.length > minSearchLength && this.state.isWellFormedFeedUrl ) { + if ( event.keyCode === 13 && this.state.searchString.length > minSearchLength && this.state.isWellFormedFeedUrl ) { event.preventDefault(); this.handleFollowToggle(); } @@ -98,11 +99,17 @@ var FollowingEditSubscribeForm = React.createClass( { }, isWellFormedFeedUrl: function( parsedUrl ) { - if ( parsedUrl.hostname && parsedUrl.hostname.indexOf( '.' ) !== -1 ) { - return true; + if ( ! parsedUrl.hostname ) { + return false; } - return false; + // Check for a valid-looking TLD + const lastHostnameSegment = last( parsedUrl.hostname.split( '.' ) ); + if ( ! lastHostnameSegment || lastHostnameSegment.length < 2 ) { + return false; + } + + return true; }, render: function() { From 44442455140ae619b7d3b1e4a4e40d7b1af9010e Mon Sep 17 00:00:00 2001 From: bluefuton Date: Tue, 24 Nov 2015 11:50:07 +0000 Subject: [PATCH 2/3] Following Management: ensure feed URL has at least one dot before activating input --- client/reader/following-edit/subscribe-form.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/reader/following-edit/subscribe-form.jsx b/client/reader/following-edit/subscribe-form.jsx index 19c487cdab9a8..5487975bbde24 100644 --- a/client/reader/following-edit/subscribe-form.jsx +++ b/client/reader/following-edit/subscribe-form.jsx @@ -99,7 +99,7 @@ var FollowingEditSubscribeForm = React.createClass( { }, isWellFormedFeedUrl: function( parsedUrl ) { - if ( ! parsedUrl.hostname ) { + if ( ! parsedUrl.hostname || parsedUrl.hostname.indexOf( '.' ) === -1 ) { return false; } From 7858dd789763bb9528c166a5dbb0661813134105 Mon Sep 17 00:00:00 2001 From: bluefuton Date: Wed, 25 Nov 2015 14:41:17 +0000 Subject: [PATCH 3/3] Use .lastIndexOf for .tld validation rather than lodash last --- client/reader/following-edit/subscribe-form.jsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/reader/following-edit/subscribe-form.jsx b/client/reader/following-edit/subscribe-form.jsx index 5487975bbde24..cd1bc44cdee29 100644 --- a/client/reader/following-edit/subscribe-form.jsx +++ b/client/reader/following-edit/subscribe-form.jsx @@ -3,8 +3,7 @@ // External dependencies const React = require( 'react' ), url = require( 'url' ), - noop = require( 'lodash/utility/noop' ), - last = require( 'lodash/array/last' ); + noop = require( 'lodash/utility/noop' ); // Internal dependencies const Search = require( 'components/search' ), @@ -104,8 +103,7 @@ var FollowingEditSubscribeForm = React.createClass( { } // Check for a valid-looking TLD - const lastHostnameSegment = last( parsedUrl.hostname.split( '.' ) ); - if ( ! lastHostnameSegment || lastHostnameSegment.length < 2 ) { + if ( parsedUrl.hostname.lastIndexOf( '.' ) > ( parsedUrl.hostname.length - 3 ) ) { return false; }