Return false for URLs that cannot be parsed in isReasonableGitUrl
What does this MR do and why?
isReasonableGitUrl checks the URL with a regex and then calls new URL(url), but some URLs pass
the regex and are still invalid (like http://256.1.1.1), so new URL throws instead of the
function returning false. This MR returns false when the URL cannot be parsed and adds the
invalid IPv4 test cases suggested in the review of !231760 (merged). It uses a try/catch instead of
URL.canParse because URL.canParse does not exist in our Jest environment (jsdom 20 uses
whatwg-url 11), and the rest of url_utility.js already uses this pattern.
Closes #597437.
Screenshots or screen recordings
Not applicable — no visual change.
How to set up and validate locally
- Run
yarn jest spec/frontend/lib/utils/url_utility_spec.js.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.
This contribution was prepared with the help of an AI assistant. I reviewed the changes and take responsibility for them.