Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate .tld for new feed URLs #325

Merged
merged 3 commits into from
Nov 25, 2015
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 || parsedUrl.hostname.indexOf( '.' ) === -1 ) {
return false;
}

return false;
// Check for a valid-looking TLD
const lastHostnameSegment = last( parsedUrl.hostname.split( '.' ) );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is fine, but you could also use lastIndexOf, compare that to length - 2 (3?), and avoid the allocations that come with split.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I like that. Changing now.

if ( ! lastHostnameSegment || lastHostnameSegment.length < 2 ) {
return false;
}

return true;
},

render: function() {
Expand Down