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

fix: escape brackets in documentation traits #401

Merged
merged 7 commits into from
Jun 10, 2021
Merged

Conversation

aajtodd
Copy link
Contributor

@aajtodd aajtodd commented Jun 9, 2021

Issue #, if available:
fixes awslabs/aws-sdk-kotlin#153

Description of changes:
Added a new model preprocessor that sanitizes all @documentation traits and replaces all square bracket pairs with html escaped equivalents. Otherwise square brackets are treated as inline markdown in KDoc (which apparently can cause compile to fail if the link is an "invalid" identifier)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@aajtodd aajtodd requested review from kggilmer and ianbotsf June 9, 2021 17:39
Comment on lines 32 to 34
// KDoc comments use inline markdown. Replace square brackets with escaped equivalents so that they
// are not rendered as invalid links
private fun sanitize(str: String): String = str.replace(Regex("(\\[)(.*)(\\])"), "[$2]")
Copy link
Contributor

Choose a reason for hiding this comment

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

Correctness: This regex won't capture nested braces or multiple braces on a line. For example:

  • a [ b [ c ] d ]a [ b [ c ] d ]
  • a [ b ] c [ d ]a [ b ] c [ d ]

This won't capture unpaired braces either, but I'm unclear if those are a problem or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unpaired braces shouldn't be a problem as far as I know since they won't be processed as inline markdown links.

@aajtodd aajtodd merged commit 87cfa07 into main Jun 10, 2021
@aajtodd aajtodd deleted the fix-generated-kdoc branch June 10, 2021 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ses fails to build due to invalid docs
2 participants