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

Jetty 9.4.x #6473 normalize only once #6474

Merged
merged 1 commit into from Jun 28, 2021

Conversation

gregw
Copy link
Contributor

@gregw gregw commented Jun 26, 2021

Fix #6473 Reduce multiple canonicalPath calls with single alias check in PathResource

@gregw gregw added this to In progress in Jetty 9.4.43 FROZEN via automation Jun 26, 2021
@gregw gregw changed the title Jetty 9.4.x 6473 normalize only once Jetty 9.4.x #6473 normalize only once Jun 26, 2021
@gregw gregw linked an issue Jun 26, 2021 that may be closed by this pull request
@gregw gregw requested review from sbordet, lorban and joakime June 26, 2021 01:53
@gregw gregw moved this from In progress to Review in progress in Jetty 9.4.43 FROZEN Jun 27, 2021
@lachlan-roberts lachlan-roberts force-pushed the jetty-9.4.x-6473-normalize-only-once branch from f6a0630 to ab49940 Compare June 27, 2021 08:06
Jetty 9.4.43 FROZEN automation moved this from Review in progress to Reviewer approved Jun 27, 2021
Jetty 9.4.43 FROZEN automation moved this from Reviewer approved to Review in progress Jun 27, 2021
janbartel
janbartel previously approved these changes Jun 28, 2021
Copy link
Contributor

@janbartel janbartel left a comment

Choose a reason for hiding this comment

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

Some comments and suggestions, but largely looks ok: difficult to review so many changes.

* <li>{@link #getParam()} - param</li>
* <li>{@link #getPath()} - /path;param1/%2e/info;param2</li>
* <li>{@link #getDecodedPath()} - /path/info</li>
* <li>{@link #getParam()} - param2</li>
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs an explanation of why we don't return param1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

*/
public static String canonicalPath(String path)
public static String canonicalURI(String path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the param a path or a uri? If it's a uri, then the param should be called uri. Also, there are so many decodeds, encodeds flying around, that it might be clearer to name the method, rather than just relying on the javadoc of the param. Suggestion: canonicalencodedURI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a uri. I will rename

*/
public static String canonicalEncodedPath(String path)
public static String canonicalPath(String path)
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, it would be clearer to call this method canonicalDecodedPath - or to keep the api the same, add this method and make canonicalPath deprecated and refer to canonicalDecodedPath.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not keen to rename this method. There is now only canonicalPath and canonicalUri, with javadoc making it clear what they are.

return null;

path = URIUtil.canonicalPath(path);
throw new MalformedURLException("null path");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change from returning null to MalformedURLException tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes - The main resource classes do not return null and few calls to addPath ever expect a null return.
So this is just making it more uniform.

@@ -300,7 +300,8 @@ public Resource addPath(String path) throws IOException
{
return new ResourceCollection(resources.toArray(new Resource[0]));
}
return null;

throw new MalformedURLException();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because I can't see how this can ever happen, as either resource or resources will be non null.
Thus throwing rather than returning null just make sure it is seen as an error if it error does somehow get there

Jetty 9.4.43 FROZEN automation moved this from Review in progress to Reviewer approved Jun 28, 2021
Jetty 9.4.43 FROZEN automation moved this from Reviewer approved to Review in progress Jun 28, 2021
janbartel
janbartel previously approved these changes Jun 28, 2021
Jetty 9.4.43 FROZEN automation moved this from Review in progress to Reviewer approved Jun 28, 2021

Path normal = path.normalize();
if (!abs.equals(normal))
return normal;
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the normalized path is to a symlink? Do we want to do the code below to resolve the target of the symlink?

Jetty 9.4.43 FROZEN automation moved this from Reviewer approved to Review in progress Jun 28, 2021
janbartel
janbartel previously approved these changes Jun 28, 2021
Jetty 9.4.43 FROZEN automation moved this from Review in progress to Reviewer approved Jun 28, 2021
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
@lachlan-roberts lachlan-roberts force-pushed the jetty-9.4.x-6473-normalize-only-once branch from bae6d23 to c2d5a82 Compare June 28, 2021 05:52
Jetty 9.4.43 FROZEN automation moved this from Reviewer approved to Review in progress Jun 28, 2021
Jetty 9.4.43 FROZEN automation moved this from Review in progress to Reviewer approved Jun 28, 2021
@gregw gregw requested a review from janbartel June 28, 2021 06:34
@gregw gregw merged commit 122a78a into jetty-9.4.x Jun 28, 2021
Jetty 9.4.43 FROZEN automation moved this from Reviewer approved to Done Jun 28, 2021
@gregw gregw deleted the jetty-9.4.x-6473-normalize-only-once branch June 28, 2021 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Improve alias checking in PathResource
3 participants