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

login-modal.jsx: Add regex for localhost IPs #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
2 changes: 1 addition & 1 deletion src/components/login-modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Login extends Component {
let tld = hostname.split('.').slice(-2).join('.');
if (tld == 'github.io') return null;
if (tld == 'netlify.com') return null;
if (tld == 'localhost') return null;
if (tld == 'localhost' || hostname.match(/^127|^0/)) return null;
Copy link
Member

Choose a reason for hiding this comment

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

Looks fine, but not ideal. What if the website address starts from 127 or 0? e.g. 127.com, or even 127.0.0.1.com

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right!
How about this constraint starts with 127 or 0 and ends with a number [0-9]
hostname.match(/(^127|^0)?([0-9]$)/)

Copy link
Member Author

Choose a reason for hiding this comment

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

Or, I could split the hostname on . and check if the last index is a digit: hostname.split('.').pop().match(/[0-9]/)

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, why not just check if hostname exactly matches 127.0.0.1 or 0.0.0.0?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought I'll handle cases of 127.x.x.x

Copy link
Member Author

Choose a reason for hiding this comment

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

@li-boxuan So should I just check for 127.0.0.1 and 0.0.0.0?

Copy link
Member

Choose a reason for hiding this comment

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

I think so, unless there is any other exception such that you have to use regex to match.

return 'https://' + hostname + '/api/v3';

})();
Expand Down