Skip to content

Commit

Permalink
Resolve Dependency correctly if the target asset is URI-encoded (#401)
Browse files Browse the repository at this point in the history
* Resolve Dependency correctly if the target asset is URI-encoded

* Resolve Dependency correctly if the target asset is URI-encoded

* revert decodeURIComponent

* Resolve Dependency correctry if the target asset is URI-encoded

* add a test code
  • Loading branch information
zacky1972 authored and devongovett committed Jan 6, 2018
1 parent 4e2ecc3 commit 9770acf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/assets/HTMLAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class HTMLAsset extends Asset {
continue;
}
if (elements && elements.includes(node.tag)) {
let assetPath = this.addURLDependency(node.attrs[attr]);
let assetPath = this.addURLDependency(decodeURIComponent(node.attrs[attr]));
if (!isURL(assetPath)) {
assetPath = urlJoin(this.options.publicURL, assetPath);
}
Expand Down
29 changes: 29 additions & 0 deletions test/encodedURI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const assert = require('assert');
const fs = require('fs');
const {bundle, assertBundleTree} = require('./utils');

describe('encodedURI', function() {
it('should support bundling files which names in encoded URI', async function() {
let b = await bundle(__dirname + '/integration/encodedURI/index.html');

assertBundleTree(b, {
name: 'index.html',
assets: ['index.html'],
childBundles: [
{
type: 'jpg',
assets: ['日本語.jpg'],
childBundles: []
}
]
});

let files = fs.readdirSync(__dirname + '/dist');
let html = fs.readFileSync(__dirname + '/dist/index.html');
for (let file of files) {
if (file !== 'index.html') {
assert(html.includes(file));
}
}
});
});
11 changes: 11 additions & 0 deletions test/integration/encodedURI/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Parcel encoded-URI testing</title>
</head>
<body>
<H1>Parcel encoded-URI testing</H1>
<img alt="日本語" src="%e6%97%a5%e6%9c%ac%e8%aa%9e.jpg" />
</body>
</html>
Binary file added test/integration/encodedURI/日本語.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9770acf

Please sign in to comment.