-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8332858: References with escapes have broken positions after they are transformed #19387
Conversation
👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into |
@lahodaj 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:
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 87 new commits pushed to the
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. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
|
||
for (char c : ref.toCharArray()) { | ||
if (Escaping.ESCAPABLE.indexOf(c) >= 0) { | ||
pattern.append("\\\\?"); |
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.
suggestion, dunno how critical is this code but regex usually are a tax on performance, I would consider not using them
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 for the belated answer. Yes, regexps are usually not very performant, but it is only happening when the exact match fails. And, hopefully, the regexp should not be too difficult to handle. I was considering writing the search by hand, and I can, but it seems like a lot of code to handle a case like this. I can write the search manually, though.
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.
ok if you think they won't be a problem in this case, I'm fine with it, we can always refactor the code if needed
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 think the use of regex is overkill. The only characters that need to be escaped, and must be escaped are \[\]
Unescaped square bracket characters are not allowed inside the opening and closing square brackets of link labels.
and, []
can only occur as such in adjacent pairs, so you ought to be able to get away with a simple ref.replaceAll("[]",
\[\]")`
While Markdown may permit these of escapes for other characters in other kinds of links, for the extended form of links (that map to {@link[plain]...}
) we specify the string must be the signature, with the only exception of needing to escape the square brackets.
Note in particular, this line, at about line 555 in this file.
var l = label.replace("\\[\\]", "[]");
All we need to do here is effectively "revert" the effect of this transformation before searching for the input text.
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.
looks good
@@ -35,6 +35,7 @@ | |||
import com.sun.source.doctree.DocCommentTree; | |||
import com.sun.source.doctree.DocTree; | |||
import com.sun.source.doctree.DocTreeVisitor; | |||
import com.sun.source.doctree.EscapeTree; |
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.
Not sure why you need this.
import java.util.regex.Matcher; | ||
import jdk.internal.org.commonmark.internal.util.Escaping; |
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.
imports out of order
|
||
for (char c : ref.toCharArray()) { | ||
if (Escaping.ESCAPABLE.indexOf(c) >= 0) { | ||
pattern.append("\\\\?"); |
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 think the use of regex is overkill. The only characters that need to be escaped, and must be escaped are \[\]
Unescaped square bracket characters are not allowed inside the opening and closing square brackets of link labels.
and, []
can only occur as such in adjacent pairs, so you ought to be able to get away with a simple ref.replaceAll("[]",
\[\]")`
While Markdown may permit these of escapes for other characters in other kinds of links, for the extended form of links (that map to {@link[plain]...}
) we specify the string must be the signature, with the only exception of needing to escape the square brackets.
Note in particular, this line, at about line 555 in this file.
var l = label.replace("\\[\\]", "[]");
All we need to do here is effectively "revert" the effect of this transformation before searching for the input text.
/reviewers 2 reviewer |
@jonathan-gibbons |
/integrate |
Going to push as commit 2ab8ab5.
Your commit was automatically rebased without conflicts. |
If the javadoc comment contains a (Markdown) link like:
The transformer that converts this link into the Javadoc link will not find the reference, as it is looking for
java.util.Arrays#asList(Object[])
(note the missing escapes), which is not present in the original text.This patch tries to fix that by permitting optional escapes for all escapable character when searching for the reference, in case the literal search fails. This is done using regexp, although could presumably be done using a manual search.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19387/head:pull/19387
$ git checkout pull/19387
Update a local copy of the PR:
$ git checkout pull/19387
$ git pull https://git.openjdk.org/jdk.git pull/19387/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19387
View PR using the GUI difftool:
$ git pr show -t 19387
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19387.diff
Webrev
Link to Webrev Comment