Skip to content

Commit

Permalink
Fix _processAssetsRequest when url contains non-latin letter
Browse files Browse the repository at this point in the history
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 #9604

Differential Revision: D3821328

Pulled By: javache

fbshipit-source-id: bfdc7f71517b5d4ba9e0a013979e5dcf6c31a237
  • Loading branch information
wusuopu authored and Facebook Github Bot 2 committed Sep 6, 2016
1 parent 79f3950 commit 8d013c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packager/react-packager/src/Server/__tests__/Server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)', () => {
Expand Down
2 changes: 1 addition & 1 deletion packager/react-packager/src/Server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8d013c2

Please sign in to comment.