-
Notifications
You must be signed in to change notification settings - Fork 8
fix(sanitizePath): ensure unicode chars are encoded as expected #70
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
Conversation
Tests
Bug Fixes
Chore
ContributorsCommit-Lint commandsYou can trigger Commit-Lint actions by commenting on this PR:
|
| public static Map<String, Boolean> checkProxyStatus(String p) { | ||
| Map<String, Boolean> status = new HashMap<String, Boolean>(); | ||
| String path = p; | ||
| path.replaceAll("^/", ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to change implementation to HashMap since JDK 8 was not very happy with Map. Makes syntax read a little differently here than in does in go.
| public static Map<String, Boolean> checkProxyStatus(String p) { | ||
| Map<String, Boolean> status = new HashMap<String, Boolean>(); | ||
| String path = p; | ||
| path.replaceAll("^/", ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this replaceAll takes a regex, is that correct?
|
|
||
| public class URLHelper { | ||
|
|
||
| private static final String IS_ENCODED = "isEncoded"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these values need to be String? The string value "isEncoded" is the same as its identifier IS_ENCODED, what if ... Boolean IS_ENCODED = false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linter was yelling at me for not storing these as a constant 🤷🏼♂️ , but I can change this around if you like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My 2¢ here, I agree with @ericdeansanchez
| .replaceAll("\\%21", "!") | ||
| .replaceAll("\\%27", "'") | ||
| .replaceAll("\\%28", "(") | ||
| .replaceAll("\\%29", ")") | ||
| .replaceAll("\\%7E", "~"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale for decoding these? I imagine it's to ensure consistency but I just wanted to be sure.
|
|
||
| public class URLHelper { | ||
|
|
||
| private static final String IS_ENCODED = "isEncoded"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My 2¢ here, I agree with @ericdeansanchez
|
Latest build fails because of test imgix-java/src/test/java/com/imgix/test/TestAll.java Lines 173 to 183 in c8e9655
Maybe we need to allow encoded proxy paths through given this was established behavior? Might need to undo 0c4f0d0 |
Yeah I think you're right, we should keep this in order to prevent a breaking change. |
| } else if (pathIsProxy.equals(true) && proxyIsEncoded.equals(true)) { | ||
| return "/" + path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conditional is needed to avoid encoded path support breaking change.
| // TODO(luis): re-enable encoded path suppport at a later date | ||
| // { | ||
| // "Absolute Path With Encoded Unicode Characters", | ||
| // | ||
| // "/example/I%20cann%C3%B8t%20bel%C3%AE%C3%A9v%E2%88%91%20it%20wor%EF%A3%BFs!%20%F0%9F%98%B1", | ||
| // | ||
| // "http://securejackangers.imgix.net/example/I%20cann%C3%B8t%20bel%C3%AE%C3%A9v%E2%88%91%20it%20wor%EF%A3%BFs!%20%F0%9F%98%B1?w=500" | ||
| // }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving this test commented for clarity's sake. Want to be explicit that encoded unicode chars are not supported in paths unless they are proxy paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused on this part, was this already supported behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry my comment isn't clear. Should say enable not re-enable. Only wanted to let next contributor know explicitly encoded UNICODE paths are not supported atm.
|
@sherwinski @ericdeansanchez double checking we're good to merge this one in |
All good from my end 👍 |
|
Had to force push since I forgot to rebase on |
Description
This PR adds test and updates the
sanitizePathmethod to ensure Unicode characters get encoded when needed and as expected. It builds off of the imgix-go implementation for encoded URLs and creates a newisASCIIEncodedmethod that validates ASCII encoding and a few more custom imgix encoding rules.