replaced deprecated url.parse with URL in parseOptionsFromUrl#1548
Closed
vzaidman wants to merge 3 commits into
Closed
replaced deprecated url.parse with URL in parseOptionsFromUrl#1548vzaidman wants to merge 3 commits into
url.parse with URL in parseOptionsFromUrl#1548vzaidman wants to merge 3 commits into
Conversation
Differential Revision: D79724370
Summary: In a codebase with non-ascii characters in file paths (e.g. Japanese or Chinese characters), metro has an error when serving bundles: ``` TypeError: Invalid character in header content ``` This was reported in the Expo project expo/expo#27397 but it's not Expo code and was later closed. The problem is fairly simple—HTTP headers need to use ASCII characters only, but filesystems are not limited to ASCII so trying to put a filesystem path directly into a HTTP header value is going to cause a problem. The solution also seems relatively simple—URL encode the path so that it uses percent encoding of non-ASCII characters. As suggested in https://velog.io/demian/RN-%EC%98%A4%EB%A5%98-%ED%95%B4%EA%B2%B0-TypeError-Invalid-character-in-header-content-X-React-Native-Project-Root, some people were adding the following middleware to fix that issue: ``` function createMetroStatusMiddleware(metroConfig) { return (_req, res)=>{ res.setHeader("X-React-Native-Project-Root", new URL(metroConfig.projectRoot)); res.end("packager-status:running"); }; } ``` Instead, I went to the root cause, and improved the parsing of the URL for both `sourceUrl` and `sourceMapUrl` fixing both the issue with serving bundles and the issue with serving source maps. > **_NOTE:_** this problem stems from using the [deprecated `url.parse` instead of the newer URL](https://nodejs.org/api/url.html#urlparseurlstring-parsequerystring-slashesdenotehost). Changelog: [General][Fixed] Metro supporting non-ASCII bundle/sourcemaps paths Pull Request resolved: react#1538 Test Plan: Using a test diff D78806803 I managed to reproduce Metro not launching RNTester before this diff. 1. `buck2 install -r rntester-android` (with the modified bundle path) 2. `DEV=1 js1 run` 3. launch `RNTester` Before- app crashes: https://pxl.cl/7LFkb After- app launches, debugging works: {F1980565661} can even add the bundle to ignore-list and then it gets ignored: {F1980565660} Differential Revision: D78799358
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D78890065 |
…eact#1548) Summary: Pull Request resolved: react#1548 Gets rid of the deprecated [`url.parse`](https://nodejs.org/api/url.html#urlparseurlstring-parsequerystring-slashesdenotehost) in favor of `URL` in `parseOptionsFromUrl`. Changelog: [Fixed] Replaced the deprecated `url.parse` with `URL` and correctly encode and decode source urls and source map urls Differential Revision: D78890065
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D78890065 |
fb2742c to
2783c0b
Compare
Contributor
|
This pull request has been merged in 71e158a. |
52 tasks
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:
Gets rid of the deprecated
url.parsein favor ofURLinparseOptionsFromUrl.Changelog: [Fixed] Replaced the deprecated
url.parsewithURLand correctly encode and decode source urls and source map urlsDifferential Revision: D78890065