Skip to content

Commit

Permalink
Following Management: check for a valid-looking .tld before activatin…
Browse files Browse the repository at this point in the history
…g feed input
  • Loading branch information
bluefuton committed Nov 24, 2015
1 parent 32d6fd4 commit 973657d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions client/reader/following-edit/subscribe-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 973657d

Please sign in to comment.