From 4fffdc3b589402b6ffbffbeaafc64904705dbe56 Mon Sep 17 00:00:00 2001 From: wusuopu Date: Tue, 6 Sep 2016 06:01:04 -0700 Subject: [PATCH] Fix _processAssetsRequest when url contains non-latin letter Summary: When I use local static files as Image resources, it will occur a 404 error if the image file's name contains some non-latin letters. The reason is that the request's url will be encoded if it contains some non-latin letters. Closes https://github.com/facebook/react-native/pull/9604 Differential Revision: D3821328 Pulled By: javache fbshipit-source-id: bfdc7f71517b5d4ba9e0a013979e5dcf6c31a237 --- react-packager/src/Server/__tests__/Server-test.js | 12 ++++++++++++ react-packager/src/Server/index.js | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/react-packager/src/Server/__tests__/Server-test.js b/react-packager/src/Server/__tests__/Server-test.js index 8f53c12e..de497d44 100644 --- a/react-packager/src/Server/__tests__/Server-test.js +++ b/react-packager/src/Server/__tests__/Server-test.js @@ -370,6 +370,18 @@ describe('processRequest', () => { expect(AssetServer.prototype.get).toBeCalledWith('imgs/a.png', 'ios'); expect(res.end).toBeCalledWith(mockData.slice(0, 4)); }); + + it('should serve assets files\'s name contain non-latin letter', () => { + const req = {url: '/assets/imgs/%E4%B8%BB%E9%A1%B5/logo.png'}; + const res = {end: jest.fn()}; + + AssetServer.prototype.get.mockImpl(() => Promise.resolve('i am image')); + + server.processRequest(req, res); + jest.runAllTimers(); + expect(AssetServer.prototype.get).toBeCalledWith('imgs/主页/logo.png', undefined); + expect(res.end).toBeCalledWith('i am image'); + }); }); describe('buildbundle(options)', () => { diff --git a/react-packager/src/Server/index.js b/react-packager/src/Server/index.js index 164b0e13..ecf670fb 100644 --- a/react-packager/src/Server/index.js +++ b/react-packager/src/Server/index.js @@ -483,7 +483,7 @@ class Server { } _processAssetsRequest(req, res) { - const urlObj = url.parse(req.url, true); + const urlObj = url.parse(decodeURI(req.url), true); const assetPath = urlObj.pathname.match(/^\/assets\/(.+)$/); const assetEvent = Activity.startEvent('Processing asset request', {asset: assetPath[1]}); this._assetServer.get(assetPath[1], urlObj.query.platform)