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

[fix] Invalid protocols are matched #31

Open
3 tasks done
jefflieb-wavy opened this issue Apr 16, 2024 · 2 comments
Open
3 tasks done

[fix] Invalid protocols are matched #31

jefflieb-wavy opened this issue Apr 16, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@jefflieb-wavy
Copy link

Describe the bug

Node.js version: v18.18.2

OS version: macOS 14.2.1

Description: If a valid protocol has extra characters preceding it, the extra characters are included in the match.

Actual behavior

urlRegexSafe({ strict: true }).exec("gaewggwhttp://localhost:3000/derp")

Produces a match that contains the entire string, including "gaewgg".

This also happens when strict is set to false.

Expected behavior

The match that is produced does not include "gaewgg"

Code to reproduce

const urlRegexSafe = require('url-regex-safe')
const match = urlRegexSafe({ strict: true }).exec("gaewggwhttp://localhost:3000/derp")
console.log(match)

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
@jefflieb-wavy
Copy link
Author

jefflieb-wavy commented Apr 16, 2024

Okay, I see that the matcher for the protocol will optionally match any a-z string followed by :, and then //. I guess I assumed from the docs that a valid protocol was one that was also known (which I realize isn't well-defined in itself). Maybe the answer to this is to just clarify what the definition of a valid protocol is in the docs. I could also see an option to only match a certain set of well-known or user-provided protocols being a solution too.

@iim-norse
Copy link

almost same problem with uppercase Site.Com regex dont understand or Site.com will be ite.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants