If protocol is not known then show unknown#296
Merged
Conversation
✅ Deploy Preview for freedevtool ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the URL parsing logic used by the URL-to-JSON tool so that when a user enters a URL/hostname without a recognized protocol (e.g. example.com), the output reports protocol: "unknown" instead of the internally prepended https.
Changes:
- Track whether the user input included a protocol matched by
KNOWN_PROTOCOLS_REGEX, and emit"unknown"when it did not. - Update unit tests to assert
"unknown"for missing protocol and add coverage for hostname/domain/tld parsing in that case. - Add an E2E test ensuring the UI output shows
"unknown"protocol for bare hostnames.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| client/src/lib/url-parser.ts | Sets protocol to "unknown" when the input lacks a known protocol (while still parsing via an internal https:// prepend). |
| tests/lib/url-parser.test.ts | Adjusts/extends unit tests for missing-protocol behavior and hostname/domain/tld parsing. |
| tests/e2e/tools/url-to-json.spec.ts | Adds an end-to-end regression test for "unknown" protocol when input has no protocol. |
Comment on lines
+35
to
38
| const userProvidedProtocol = KNOWN_PROTOCOLS_REGEX.test(urlToParse); | ||
| if (!userProvidedProtocol) { | ||
| urlToParse = `https://${urlToParse}`; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #285
When a user enters a bare hostname (e.g.
example.com) into the URL to JSONtool without specifying a protocol, the parser was internally prepending
https://to satisfy theURLAPI and then returningprotocol: "https"inthe output — a value the user never typed.
Changes
client/src/lib/url-parser.ts: Before thehttps://prepend, capturewhether the user's input contained a known protocol via
KNOWN_PROTOCOLS_REGEX.If not, return
protocol: "unknown"instead of the auto-prepended value. Allother fields (
hostname,domain,tld, etc.) continue to resolve correctlyvia the internal prepend.
tests/lib/url-parser.test.ts: Updated the existing"adds https:// when protocol is missing"test to assert"unknown"andrenamed it to reflect correct behaviour. Added a companion test verifying that
hostname,domain, andtldstill parse correctly when no protocol is given.tests/e2e/tools/url-to-json.spec.ts: New end-to-end test — inputsexample.com, assertsprotocol === "unknown"andhostname === "example.com".