Skip to content

Commit

Permalink
Fix bundling assets with a path outside of the project root
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis authored and thymikee committed Feb 18, 2020
1 parent 3b66615 commit 4f75146
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,16 @@ describe('getAssetDestPathAndroid', () => {
path.normalize('raw/app_test_video.mp4'),
);
});

it('should handle assets with a relative path outside of root', () => {
const asset = {
name: 'icon',
type: 'png',
httpServerLocation: '/assets/../../test',
};

expect(getAssetDestPathAndroid(asset, 1)).toBe(
path.normalize('drawable-mdpi/__test_icon.png'),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ describe('getAssetDestPathIOS', () => {
path.normalize('assets/test/icon@3x.png'),
);
});

it('should handle assets with a relative path outside of root', () => {
const asset = {
name: 'icon',
type: 'png',
httpServerLocation: '/assets/../../test',
};

expect(getAssetDestPathIOS(asset, 1)).toBe(
path.normalize('assets/__test/icon.png'),
);
});
});
8 changes: 7 additions & 1 deletion packages/cli/src/commands/bundle/getAssetDestPathIOS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import {PackagerAsset} from './assetPathUtils';
function getAssetDestPathIOS(asset: PackagerAsset, scale: number): string {
const suffix = scale === 1 ? '' : `@${scale}x`;
const fileName = `${asset.name + suffix}.${asset.type}`;
return path.join(asset.httpServerLocation.substr(1), fileName);
return path.join(
// Assets can have relative paths outside of the project root.
// Replace `../` with `_` to make sure they don't end up outside of
// the expected assets directory.
asset.httpServerLocation.substr(1).replace(/\.\.\//g, '_'),
fileName,
);
}

export default getAssetDestPathIOS;

0 comments on commit 4f75146

Please sign in to comment.