Skip to content

8272702: Resolving URI relative path with no / may lead to incorrect toString #8899

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

Closed
wants to merge 4 commits into from

Conversation

tkiriyama
Copy link
Contributor

@tkiriyama tkiriyama commented May 26, 2022

Consider an authority component without trailing "/" as a base URI. When resolving a relative path against this base URI, the resulting URI is a concatenated URI without "/".
This behaviour should be fixed, which is rationalized by rfc3986#section-5.2.3.
Could you review this fix?


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8272702: Resolving URI relative path with no / may lead to incorrect toString

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/8899/head:pull/8899
$ git checkout pull/8899

Update a local copy of the PR:
$ git checkout pull/8899
$ git pull https://git.openjdk.org/jdk pull/8899/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 8899

View PR using the GUI difftool:
$ git pr show -t 8899

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/8899.diff

@bridgekeeper
Copy link

bridgekeeper bot commented May 26, 2022

👋 Welcome back tkiriyama! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label May 26, 2022
@openjdk
Copy link

openjdk bot commented May 26, 2022

@tkiriyama The following label will be automatically applied to this pull request:

  • net

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the net net-dev@openjdk.org label May 26, 2022
@mlbridge
Copy link

mlbridge bot commented May 26, 2022

Webrevs

@aivanov-jdk
Copy link
Member

@tkiriyama You're using the wrong bugid. JDK-8272707 has nothing to do with URI. Please use the correct bugid.

@tkiriyama tkiriyama changed the title 8272707: Resolving URI relative path with no / may lead to incorrect toString 8272702: Resolving URI relative path with no / may lead to incorrect toString May 30, 2022
@tkiriyama
Copy link
Contributor Author

You're using the wrong bugid. JDK-8272707 has nothing to do with URI. Please use the correct bugid.

I'm sorry, I made a mistake.
JDK-8272702 is correct. I fixed it.

Comment on lines 2136 to 2140
if (i >= 0) {
sb.append(base, 0, i + 1);
} else {
sb.append("/");
}
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong as it will cause URI.create("foo").resolve(URI.create("test")) to return "/test" instead of "test"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your comment is correct. The behavior of specifying a relative URI as the base URI should not change, although rfc2396 recommended that the base URI be an absolute URI.
I modified to add "/" only if the given base URI is an absolute URI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dfuch
Could you review this fix again, please?

Copy link
Member

Choose a reason for hiding this comment

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

I will have a look but analyzing the proposed fix and thinking about the potential side effects will take me some time.

Copy link
Contributor Author

@tkiriyama tkiriyama Jul 6, 2022

Choose a reason for hiding this comment

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

@dfuch
I merged the latest source code and modified this fix again to resolve conflicts. Please check it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dfuch
I'm sorry to bother you, is there anything wtong in this fix?

@Michael-Mc-Mahon
Copy link
Member

It seems like URI is currently behaving to spec. Even though the behavior is surprising, it's a corner case that isn't anticipated by the spec (or RFC 2396 for that matter). It looks like this was corrected in RFC 3986, but the whole resolution algorithm is specified differently in RFC 3986. I agree we would need to better understand the potential for incompatibility by making this change, eg how does it affect resolution + relativization round trips in these cases?

@Michael-Mc-Mahon
Copy link
Member

I've thought about this some more and it does seem like the intent of RFC 2396 is clearly that an absolute URI should always have an absolute path (beginning with "/"). This implies when resolving a relative reference such as "test" against an absolute URI with an empty path, this implies a "/" needs to be added. RFC 3986 makes this explicit.

Existing code is probably working around the issue by adding a "/" explicitly when none present prior to resolution of the reference. I think we should go ahead with the change and I'm happy to sponsor it.

@openjdk
Copy link

openjdk bot commented Aug 11, 2022

@tkiriyama This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8272702: Resolving URI relative path with no / may lead to incorrect toString

Reviewed-by: dfuchs, michaelm

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 582 new commits pushed to the master branch:

  • 27b0f77: 8292318: Memory corruption in remove_dumptime_info
  • 9a65524: 8290300: Use standard String-joining tools where applicable
  • f9004fe: 8292561: Make "ReplayCompiles" a diagnostic product switch
  • 2fbb936: 8292691: Move CompilerConfig::is_xxx() inline functions out of compilerDefinitions.hpp
  • 3601e30: 8290909: MemoryPoolMBean/isUsageThresholdExceeded tests failed with "isUsageThresholdExceeded() returned false, and is still false, while threshold = MMMMMMM and used peak = NNNNNNN"
  • 37c0a13: 8292350: Use static methods for hashCode/toString primitives
  • 4453200: 8292628: x86: Improve handling of constants in trigonometric stubs
  • 07c9ba7: 8292686: runtime/cds/appcds/TestWithProfiler.java SIGSEGV in TableStatistics ctr
  • 235151e: 8292676: Remove two kerberos tests from problem list
  • df5209e: 8292683: Remove BadKeyUsageTest.java from Problem List
  • ... and 572 more: https://git.openjdk.org/jdk/compare/649f2d8835027128c6c8cf37236808094a12a35f...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@dfuch, @Michael-Mc-Mahon) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 11, 2022
Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

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

I agree with Michael. I did a deep dive in the URI code and conducted some experiments with the proposed fix and am happy with the results. I also double checked with the JCK tests for api/java_net and they were still happy. I believe this is good to go. Thanks for persisting with this one!

@dfuch
Copy link
Member

dfuch commented Aug 15, 2022

@tkiriyama please /integrate and one of us will sponsor.

@tkiriyama
Copy link
Contributor Author

/integrate

@tkiriyama
Copy link
Contributor Author

I'm sorry for the late reply. I appreciate all reviews.

@dfuch
Can I ask you to sponsor this fix?

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Aug 22, 2022
@openjdk
Copy link

openjdk bot commented Aug 22, 2022

@tkiriyama
Your change (at version d64e86b) is now ready to be sponsored by a Committer.

@dfuch
Copy link
Member

dfuch commented Aug 22, 2022

/sponsor

@openjdk
Copy link

openjdk bot commented Aug 22, 2022

Going to push as commit 79597f1.
Since your change was applied there have been 585 commits pushed to the master branch:

  • 7b5f9ed: 8288966: Better handle very spiky promotion in G1
  • 07c7977: 8290249: Vectorize signum on AArch64
  • a3ec0bb: 8253413: [REDO] [REDO] G1 incorrectly limiting young gen size when using the reserve can result in repeated full gcs
  • 27b0f77: 8292318: Memory corruption in remove_dumptime_info
  • 9a65524: 8290300: Use standard String-joining tools where applicable
  • f9004fe: 8292561: Make "ReplayCompiles" a diagnostic product switch
  • 2fbb936: 8292691: Move CompilerConfig::is_xxx() inline functions out of compilerDefinitions.hpp
  • 3601e30: 8290909: MemoryPoolMBean/isUsageThresholdExceeded tests failed with "isUsageThresholdExceeded() returned false, and is still false, while threshold = MMMMMMM and used peak = NNNNNNN"
  • 37c0a13: 8292350: Use static methods for hashCode/toString primitives
  • 4453200: 8292628: x86: Improve handling of constants in trigonometric stubs
  • ... and 575 more: https://git.openjdk.org/jdk/compare/649f2d8835027128c6c8cf37236808094a12a35f...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Aug 22, 2022
@openjdk openjdk bot closed this Aug 22, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Aug 22, 2022
@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Aug 22, 2022
@openjdk
Copy link

openjdk bot commented Aug 22, 2022

@dfuch @tkiriyama Pushed as commit 79597f1.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated net net-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

4 participants