RFR: 8332858: References with escapes have broken positions after they are transformed

Jonathan Gibbons jjg at openjdk.org
Tue May 28 22:12:02 UTC 2024


On Tue, 28 May 2024 19:07:06 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>> 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.
>
> 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

I think the use of regex is overkill, but maybe not inherently wrong. 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](https://spec.commonmark.org/0.31.2/#link-label).

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("\[\]", "[]");

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/19387#discussion_r1617939624


More information about the compiler-dev mailing list