dnault / therapi-runtime-javadoc

Read Javadoc comments at run time.
Apache License 2.0
117 stars 19 forks source link

Version 0.11.0 introduced a bug in usage formatting (missing character escapes) #53

Closed bbottema closed 2 years ago

bbottema commented 2 years ago

Version 0.11.0 introduces bug.

I'm printing the usage of a command, which works fine up until 0.10.0, but breaks in 0.11.0:

CommandLine.usage(new CommandLine(command).setUsageHelpWidth(textWidth), out, COLOR_SCHEME);

Which results in:

java.util.MissingFormatArgumentException: Format specifier '%s'

image

Please let me know if you need anything else. It's not trivial though to show you how the command is produced in my code, which is all automatic with reflection.

bbottema commented 2 years ago

I suspect this is because the source string contains a % which should be escaped by your library:

image

Indeed in older versions this is escaped properly:

image

For completion sake, here's the relevant source Javadoc:

image

dnault commented 2 years ago

I cannot reproduce the reported behavior of % being escaped as %% in 0.9.0 or 0.10.0. Could it be something the custom comment formatter was doing?

The percent character (%) has no special meaning in Javadoc or HTML. The library has no way of knowing the comment will be passed to String.format(), so escaping % by replacing it with %% is the application's responsibility.

bbottema commented 2 years ago

I found the issue and indeed it's on my side. I escape %s so that it works with Picocli (CLI library), but Therapi calls formatting methods a little differently from 0.9.0 and later versions.

For example Some sentence {@code blah} rest of sentence. is formatted completely as a CommentText renderText() (if you replace the code element manually, which I do), but in later versions I suppose this changed and the various types of text are extracted before passing the CommentText in chopped up blocks so that now a {@code xxx} block is always parsed and formatted as InlineTag with name "code". And in this formatting function I did not apply the escaping (yet).

Everything works now after I fixed my code formatting implementation.

I suppose that means I can clean up my renderText implementation as well, so it doesn't try to format inline code anymore.

bbottema commented 2 years ago

Almost, I can leave out {@code xxx} but not <code>ccc</code>. Why are these treated differently?

I understand that these are different Javadoc constructs from a syntax point of view, but from user perspective they should be treated equally, no?