-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow non-ascii header values & add utf-8 filename fallback (#35060)
Summary: Fix #31537: [Android] React Native strips non-ASCII characters from HTTP headers ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [Android] [Changed] - Allow non-ascii header values on Android and add utf-8 filename fallback in FormData Pull Request resolved: #35060 Test Plan: 1. Clone the `react-native` repo. 2. Build the rn-tester app. 3. Prepare tests 1. Add `android:usesCleartextTraffic="true"` to AndroidManifest.xml 2. Use the following code as a server: ```javascript const http = require('http'); const requestListener = function (req, res) { // raw header value console.log(req.headers['content-disposition']); // nodejs assumes the header value is ISO-8859-1 encoded console.log(Buffer.from(req.headers['content-disposition'], 'latin1').toString('utf-8')); // decode encoded header value if it's sent as UTF-8 console.log(decodeURI(req.headers['content-disposition'])); res.writeHead(200); res.end(); }; const server = http.createServer(requestListener); server.listen(3000); ``` 3. Run `adb reverse tcp:3000 tcp:3000` to connect the 3000 port on the emulator if necessary. 4. Edit `RNTesterAppShared.js` to include test code: ```javascript useEffect(() => { fetch('http://localhost:3000/', { headers: { 'Content-Type': 'multipart/form-data; charset=utf-8', 'Content-Disposition': `attachment; filename*=utf-8''${encodeURI( 'filename测试abc.jpg', )}`, }, }).then(res => { console.log(res.ok); }); fetch('http://localhost:3000/', { headers: { 'Content-Type': 'multipart/form-data; charset=utf-8', 'Content-Disposition': `attachment; filename="filename测试abc.jpg"`, }, }).then(res => { console.log(res.ok); }); }, []); ``` 5. Both requests should succeed; without the fix, the second request received by the server will not have the utf-8 characters "测试" in the header value. Reviewed By: NickGerleman Differential Revision: D40639985 Pulled By: cortinico fbshipit-source-id: 005f2481976046a92a26239ad704780ac58d4a44
- Loading branch information
1 parent
8b2f324
commit 7c7e9e6
Showing
6 changed files
with
33 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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