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

feat(isUrl): urls with empty user #1833

Merged

Conversation

MiguelSavignano
Copy link
Contributor

URL with an empty user are valid.

Example:

http://:pass@www.foobar.com/

This kind of URL (${protocol}://:${password}@${hostname}:${port}) can be parsed and allows to extract the password.
discussion: #1681

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)

@codecov
Copy link

codecov bot commented Oct 27, 2021

Codecov Report

Merging #1833 (7e6370d) into master (13651ea) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1833   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          102       102           
  Lines         2029      2032    +3     
  Branches       457       458    +1     
=========================================
+ Hits          2029      2032    +3     
Impacted Files Coverage Δ
src/lib/isURL.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13651ea...7e6370d. Read the comment docs.

src/lib/isURL.js Outdated
Comment on lines 117 to 121
const user_password = split[0].split(':');
if (user_password[0] === '' && user_password[1] === '') {
return false;
}
auth = split.shift();

Choose a reason for hiding this comment

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

Or like this :)

    auth = split.shift();
    if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
      return false;
    }
    const [user, password] = auth.split(':');
    if (user === '' && password === '') {
      return false;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your contrib! 🎉

@profnandaa profnandaa merged commit 28f899d into validatorjs:master Oct 30, 2021
theteladras pushed a commit to theteladras/validator.js that referenced this pull request Oct 30, 2021
* allow urls with empty user

* use array extract

* reuse auth split
profnandaa pushed a commit that referenced this pull request Oct 31, 2021
* allow urls with empty user

* use array extract

* reuse auth split
profnandaa pushed a commit that referenced this pull request Oct 31, 2021
* allow urls with empty user

* use array extract

* reuse auth split
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants