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

Escape javadoc special characters #1342

Merged
merged 1 commit into from
Apr 30, 2024
Merged

Escape javadoc special characters #1342

merged 1 commit into from
Apr 30, 2024

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Apr 26, 2024

Description

Fixes #1271

Correctly scope comment escapes to outside of code blocks. The resulting code is both more idiomatic javadoc and safe to embed.

I have two motivating examples:

  1. Correctness: Upstream comments that start lines with @pattern will now be escaped to {@literal @}pattern. This has prevented us from publishing in the past (A release workflow silently fails for Java sdk pulumi-gcp#1950, Java SDK does not pass javadoc pulumi-auth0#516, Java SDK does not pass javadoc pulumi-azure#1979)

  2. Idiomaticity: Generated code blocks will no longer be HTML escaped (since they don't need to be). Instead, they will render correctly.

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

@iwahbe iwahbe self-assigned this Apr 26, 2024
@iwahbe iwahbe added the impact/no-changelog-required This issue doesn't require a CHANGELOG update label Apr 26, 2024
return formatForeignBlockCommentFrom(comment, 0, indent)
}

// formatForeignBlockCommentFrom is like [formatForeignBlockComment], except that it
Copy link
Member

Choose a reason for hiding this comment

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

Style nit for helper functions fHelper that are only called from f and are not supposed to be used anywhere else I personally forgo the doc comments

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not a helper function. It's called directly from the rest of the module. It's used for generating comments like:

fprintf(w, formatForeignBlockCommentFrom("@return "+invoke.Comment, 1))

That way any @ in the invoke.Comment string is escaped but the first @ of the @return is left alone.

// Then write the code block itself
dst.WriteString(code(comment[codeStart:codeEndOffset]))
// Then adjust copiedTo to start after the code block
comment = comment[codeEndOffset:]
Copy link
Member

Choose a reason for hiding this comment

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

Old-fashioned scanner FTW.

Copy link
Member

@t0yv0 t0yv0 left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this!

@t0yv0 t0yv0 merged commit 50d31e9 into main Apr 30, 2024
22 checks passed
@t0yv0 t0yv0 deleted the iwahbe/escape-javadoc-at branch April 30, 2024 15:16
t0yv0 added a commit that referenced this pull request May 1, 2024
t0yv0 added a commit that referenced this pull request May 1, 2024
Reverts #1342

Testing this out on pulumi/pulumi-azure#1992 it
appears that the latest version still cannot properly escape the
generated code, moreover it seems to have regressed on not escaping `->`
properly which might further break things. I think we might be better
off reverting for now until we work this out to pass more test cases.

Apologies for merging that without diving deeper - it looked solid at
code review time, I guess we don't have downstream checks here yet to
demonstrate that derivative providers cannot build with the changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/no-changelog-required This issue doesn't require a CHANGELOG update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ignore or escape unintended javadoc comments
2 participants