Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow spaces in filenames #1212

Merged
merged 12 commits into from
Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ class Asset {
from = this.name;
}

const parsed = URL.parse(url);
const parsed = URL.parse(decodeURIComponent(url));
const resolved = path.resolve(path.dirname(from), parsed.pathname);
this.addDependency(
'./' + path.relative(path.dirname(this.name), resolved),
'./' +
path.relative(path.dirname(this.name), decodeURIComponent(resolved)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't resolved already be decoded here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL.parse url encodes the parsed string.
I've pushed a fix as originally I thought the parsed url's encoding was important (therefore decoding twice), but it isn't as we create new filenames anyway.
Now it only decodes once saving some ms of building.

Object.assign({dynamic: true}, opts)
);

Expand Down
2 changes: 1 addition & 1 deletion src/assets/HTMLAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class HTMLAsset extends Asset {
}

processSingleDependency(path, opts) {
let assetPath = this.addURLDependency(decodeURIComponent(path), opts);
let assetPath = this.addURLDependency(path, opts);
if (!isURL(assetPath)) {
assetPath = urlJoin(this.options.publicURL, assetPath);
}
Expand Down
16 changes: 16 additions & 0 deletions test/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,20 @@ describe('html', function() {
]
});
});

it('should resolve assets containing spaces', async function() {
let b = await bundle(__dirname + '/integration/resolve-spaces/index.html');

assertBundleTree(b, {
name: 'index.html',
assets: ['index.html'],
childBundles: [
{
type: 'html',
assets: ['other page.html'],
childBundles: []
}
]
});
});
});
6 changes: 6 additions & 0 deletions test/integration/resolve-spaces/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!doctype html>
<html>
<body>
<a href="other page.html">other page</a>
</body>
</html>
6 changes: 6 additions & 0 deletions test/integration/resolve-spaces/other page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!doctype html>
<html>
<body>
<a href="index.html">index</a>
</body>
</html>