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

Resolve Dependency correctly if the target asset is URI-encoded #401

Merged
merged 8 commits into from
Jan 6, 2018

Conversation

zacky1972
Copy link
Contributor

This patch fixes the bug that parcel can't read assets including encoded URI such as:

<img src="images/%e6%97%a5%e6%9c%ac%e8%aa%9e.jpg" />

@devongovett
Copy link
Member

I think this should be specific to HTML assets. We don't want to double decode in the case where something has a legit percent symbol in the filename.

@brandon93s
Copy link
Contributor

I agree on the HTML asset only piece. Let's limit this to the use case.

A few more thoughts:

  • decodeURIComponent only supports UTF-8. If someone chooses to use ISO-8859-1 or other on their site, this is going to throw an exception. We need to handle this or provide a sensible error message. The asset failure shouldn't cascade into a decode failure.

  • With that in mind, the current implementation could throw in the catch block for encoding that isn't UTF-8, which would not be desirable.

  • I'd prefer error messages show the original asset name, not a decoded name. When debugging, I'd want to see the values present in my source not their decoded representations.

@brandon93s brandon93s changed the title Resolve Dependency correctly if the target asset is URI-encoded [WIP] Resolve Dependency correctly if the target asset is URI-encoded Dec 27, 2017
@zacky1972
Copy link
Contributor Author

Thank you for your comments.

I'd like to reorganize this patch into the HTML asset, but I can't understand where I should insert the patch into the source code of the HTML asset. Help me!

@shawwn
Copy link
Contributor

shawwn commented Dec 30, 2017 via email

@zacky1972
Copy link
Contributor Author

Thank you! I sent a Slack message, just now.

@zacky1972
Copy link
Contributor Author

I've just pushed PR worked with shawwn.
Please review it, again!

@shawwn
Copy link
Contributor

shawwn commented Jan 4, 2018

@devongovett @brandon93s This PR looks good to me now. Any further thoughts?

I think the UTF-8 concern is good, but we might want to merge this for now. Supporting at least one Japanese user is better than supporting all hypothetical foreign users, and @zacky1972 has spent a lot of time on this already.

@devongovett
Copy link
Member

Would be awesome to add a test if possible, but it looks good to me otherwise!

@zacky1972
Copy link
Contributor Author

OK! I'd like to add a test.

@zacky1972
Copy link
Contributor Author

I add a test code.

But, I found another problem. This patch assumes encoding of the file system is UTF-8.
If encoding is CP932, which is used in Windows in Japan, or EUC-JP, which is used in old UNIX system in Japan, the patch might be unworkable.

I'd like to test such systems, but I don't have them.

@zacky1972
Copy link
Contributor Author

zacky1972 commented Jan 5, 2018

I call for help by Twitter and Facebook.

https://twitter.com/zacky1972/status/949342180430237697
https://www.facebook.com/zacky1972/posts/1799791536720470

parcel ユーザーで,ファイルシステムが UTF-8 でない Windows や Linux 等をお使いの方いらっしゃいませんか? テストにご協力ください!#拡散希望

This means:

Help us, if you use parcel and encoding of the file system of your PC (Windows or Linux etc.) is not UTF-8! #RetweetMe

@devongovett
Copy link
Member

I think Node will handle converting from UTF8 and back for us, but it would be good to verify. Some info here: https://nodejs.org/api/fs.html#fs_buffer_api

@zacky1972
Copy link
Contributor Author

Oh, really!
I hope this patch works in non-UTF-8 file systems...

@brandon93s
Copy link
Contributor

brandon93s commented Jan 5, 2018

That seems true for the encoding of the files, but decodeURIComponent itself only handles UTF-8 though (and will throw otherwise), even in node. More details: sindresorhus/got#420.

We may want to take a "try-decode" approach here, continuing with the raw value if decoding fails.

@devongovett devongovett changed the title [WIP] Resolve Dependency correctly if the target asset is URI-encoded Resolve Dependency correctly if the target asset is URI-encoded Jan 6, 2018
@devongovett
Copy link
Member

Let's get this in and deal with any other encoding issues as they come up. Thanks for your work on this @zacky1972!

@devongovett devongovett merged commit 9770acf into parcel-bundler:master Jan 6, 2018
@zacky1972
Copy link
Contributor Author

You're welcome!
I'd like to continue to support parcel, not only about this issue but also about any other issues if I can!

@zacky1972
Copy link
Contributor Author

I've confirmed it on Windows PC of the Japanese edition, and it works well.

devongovett pushed a commit that referenced this pull request Oct 15, 2018
* 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
devongovett pushed a commit that referenced this pull request Oct 15, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants