-
Notifications
You must be signed in to change notification settings - Fork 257
Manually parse urls #2674
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
Merged
Merged
Manually parse urls #2674
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
96cb9ba
test: :white_check_mark: fix react native test, removing need for pol…
gingerbenw 1f587bc
refactor: :recycle: update query parameter parsing
gingerbenw 90a545f
remove use of url.search
gingerbenw a6dacec
remove URLSearchParams
gingerbenw 9883389
Find the earliest occurrence of '/', '?', or '#' to determine the dom…
gingerbenw 7e7c468
docs: add CHANGELOG entry
gingerbenw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
45 changes: 15 additions & 30 deletions
45
packages/plugin-network-instrumentation/lib/redact-query-parameters.js
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
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,38 +1,23 @@ | ||||||||||
| const parseQueryParams = require('./parse-query-params') | ||||||||||
| const redactValues = require('./redact-values') | ||||||||||
|
|
||||||||||
| function isAbsoluteURL (url) { | ||||||||||
| try { | ||||||||||
| // eslint-disable-next-line no-new | ||||||||||
| new URL(url) | ||||||||||
| return true | ||||||||||
| } catch (e) { | ||||||||||
| return false | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| module.exports = function (url, redactedKeys) { | ||||||||||
| const isAbsolute = isAbsoluteURL(url) | ||||||||||
| const base = isAbsolute ? undefined : 'http://localhost' | ||||||||||
|
|
||||||||||
| // Parse the URL - use a base only for relative URLs | ||||||||||
| const urlObj = new URL(url, base) | ||||||||||
| const params = new URLSearchParams(urlObj.search) | ||||||||||
|
|
||||||||||
| // Convert URLSearchParams to object without using Object.fromEntries() | ||||||||||
| const paramsObject = {} | ||||||||||
| params.forEach((value, key) => { | ||||||||||
| paramsObject[key] = value | ||||||||||
| }) | ||||||||||
|
|
||||||||||
| const paramsObject = parseQueryParams(url) | ||||||||||
| const redactedParams = redactValues(paramsObject, redactedKeys) | ||||||||||
| urlObj.search = new URLSearchParams(redactedParams).toString() | ||||||||||
| const redactedQueryString = Object.entries(redactedParams).map(([key, value]) => `${key}=${value}`).join('&') | ||||||||||
|
||||||||||
| const redactedQueryString = Object.entries(redactedParams).map(([key, value]) => `${key}=${value}`).join('&') | |
| const redactedQueryString = Object.entries(redactedParams) | |
| .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`) | |
| .join('&') |
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
2 changes: 1 addition & 1 deletion
2
test/react-native/features/fixtures/expected_http_errors/401.json
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
2 changes: 1 addition & 1 deletion
2
test/react-native/features/fixtures/expected_http_errors/500.json
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Query parameter values should be URI-encoded when constructing the query string. Without encoding, special characters (like '&', '=', or spaces) in parameter values will break the URL format. Use
encodeURIComponent(value)when building the query string.