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
This commit is contained in:
wusuopu 2016-09-06 06:01:04 -07:00 committed by Facebook Github Bot 2
parent 777ea1cbdc
commit 4fffdc3b58
2 changed files with 13 additions and 1 deletions

View File

@ -370,6 +370,18 @@ describe('processRequest', () => {
expect(AssetServer.prototype.get).toBeCalledWith('imgs/a.png', 'ios'); expect(AssetServer.prototype.get).toBeCalledWith('imgs/a.png', 'ios');
expect(res.end).toBeCalledWith(mockData.slice(0, 4)); 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)', () => { describe('buildbundle(options)', () => {

View File

@ -483,7 +483,7 @@ class Server {
} }
_processAssetsRequest(req, res) { _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 assetPath = urlObj.pathname.match(/^\/assets\/(.+)$/);
const assetEvent = Activity.startEvent('Processing asset request', {asset: assetPath[1]}); const assetEvent = Activity.startEvent('Processing asset request', {asset: assetPath[1]});
this._assetServer.get(assetPath[1], urlObj.query.platform) this._assetServer.get(assetPath[1], urlObj.query.platform)