mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Fix https://github.com/facebook/react-native/issues/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: https://github.com/facebook/react-native/pull/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