Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@luqven
Copy link
Contributor

@luqven luqven commented Apr 1, 2021

Description

This PR adds test and updates the sanitizePath method 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 new isASCIIEncoded method that validates ASCII encoding and a few more custom imgix encoding rules.

@luqven luqven self-assigned this Apr 1, 2021
@commit-lint
Copy link

commit-lint bot commented Apr 1, 2021

Tests

  • buildURL: ensure unicode charas get encoded (a94f952)
  • BuildUrl: add more unicdoe tests (2901112)
  • buildUrl: disable encoded unicode test for now (e17c687)
  • unicode: reword todo comment (39758e4)

Bug Fixes

  • sanatizePath: ensure unicode chars encoded (36da74c)

Chore

  • checkProxy: use hashmap for jdk 8 compat (df9d46b)
  • sanitizePath: fix method name spelling (e57dfc0)
  • decode: remove unused fn again (dc0cebb)
  • checkProxyStatus: use bool instead of str vars (bb16c43)
  • checkProxyStatus: remove encodedHTTP support for now (6a60952)
  • santiizePath: accept encoded proxy paths (66822f0)
  • sanitizePath: disable ascii encoded path (ab1c87b)
  • URLHelper: remove unused isAscii method (14cf5de)

Contributors

luqven

Commit-Lint commands

You can trigger Commit-Lint actions by commenting on this PR:

  • @Commit-Lint merge patch will merge dependabot PR on "patch" versions (X.X.Y - Y change)
  • @Commit-Lint merge minor will merge dependabot PR on "minor" versions (X.Y.Y - Y change)
  • @Commit-Lint merge major will merge dependabot PR on "major" versions (Y.Y.Y - Y change)
  • @Commit-Lint merge disable will desactivate merge dependabot PR
  • @Commit-Lint review will approve dependabot PR
  • @Commit-Lint stop review will stop approve dependabot PR

@luqven luqven changed the base branch from main to luis/pathEncodingFix April 1, 2021 15:10
Comment on lines +173 to +176
public static Map<String, Boolean> checkProxyStatus(String p) {
Map<String, Boolean> status = new HashMap<String, Boolean>();
String path = p;
path.replaceAll("^/", "");
Copy link
Contributor Author

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("^/", "");
Copy link
Contributor

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";
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

@luqven luqven marked this pull request as ready for review April 2, 2021 19:05
@luqven luqven requested a review from a team as a code owner April 2, 2021 19:05
Comment on lines +252 to +249
.replaceAll("\\%21", "!")
.replaceAll("\\%27", "'")
.replaceAll("\\%28", "(")
.replaceAll("\\%29", ")")
.replaceAll("\\%7E", "~");
Copy link
Contributor

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";
Copy link
Contributor

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

@luqven luqven requested a review from sherwinski April 5, 2021 13:31
@luqven
Copy link
Contributor Author

luqven commented Apr 5, 2021

Latest build fails because of test testHelperBuildSignedURLWithWebProxyWithEncoding()

public void testHelperBuildSignedURLWithWebProxyWithEncoding() {
URLHelper uh =
new URLHelper(
"jackttl2.imgix.net",
"http%3A%2F%2Fa.abcnews.com%2Fassets%2Fimages%2Fnavigation%2Fabc-logo.png%3Fr%3D20",
"http",
"JHrM2ezd");
assertEquals(
"http://jackttl2.imgix.net/http%3A%2F%2Fa.abcnews.com%2Fassets%2Fimages%2Fnavigation%2Fabc-logo.png%3Fr%3D20?s=cf82defe3436a957262d0e64c21e72f9",
uh.getURL());
}

Maybe we need to allow encoded proxy paths through given this was established behavior? Might need to undo 0c4f0d0

@sherwinski
Copy link
Contributor

Latest build fails because of test testHelperBuildSignedURLWithWebProxyWithEncoding()

public void testHelperBuildSignedURLWithWebProxyWithEncoding() {
URLHelper uh =
new URLHelper(
"jackttl2.imgix.net",
"http%3A%2F%2Fa.abcnews.com%2Fassets%2Fimages%2Fnavigation%2Fabc-logo.png%3Fr%3D20",
"http",
"JHrM2ezd");
assertEquals(
"http://jackttl2.imgix.net/http%3A%2F%2Fa.abcnews.com%2Fassets%2Fimages%2Fnavigation%2Fabc-logo.png%3Fr%3D20?s=cf82defe3436a957262d0e64c21e72f9",
uh.getURL());
}

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.

Comment on lines 277 to 269
} else if (pathIsProxy.equals(true) && proxyIsEncoded.equals(true)) {
return "/" + path;
Copy link
Contributor Author

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.

Comment on lines 148 to 155
// 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"
// },
Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@luqven luqven requested a review from ericdeansanchez April 9, 2021 02:50
@luqven
Copy link
Contributor Author

luqven commented Apr 9, 2021

@sherwinski @ericdeansanchez double checking we're good to merge this one in

@sherwinski
Copy link
Contributor

@sherwinski @ericdeansanchez double checking we're good to merge this one in

All good from my end 👍

Base automatically changed from luis/pathEncodingFix to main April 12, 2021 15:20
@luqven
Copy link
Contributor Author

luqven commented Apr 12, 2021

Had to force push since I forgot to rebase on luis/pathEncodingFix before it got merged in to main. Apols.

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