Permalink
Browse files

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 #9604

Differential Revision: D3821328

Pulled By: javache

fbshipit-source-id: bfdc7f71517b5d4ba9e0a013979e5dcf6c31a237
  • Loading branch information...
1 parent 79f3950 commit 8d013c2326fe657fa781a79ddfacedce32c47619 @wusuopu wusuopu committed with Facebook Github Bot 2 Sep 6, 2016
@@ -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)', () => {
@@ -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)

0 comments on commit 8d013c2

Please sign in to comment.