Fix HTML-reserved characters ('&', '<', etc) not rendered correctly in entry preview#10733
Merged
Siedlerchr merged 11 commits intoJan 23, 2024
Merged
Conversation
94359b2 to
078682b
Compare
calixtus
previously approved these changes
Jan 1, 2024
Member
|
Looks good so far, how about some simple tests? |
koppor
requested changes
Jan 2, 2024
koppor
left a comment
Member
There was a problem hiding this comment.
I have one minor feedback (also via /review by Codium
Consider using a compiled Pattern for the regex in normalizedFiled method to improve performance.
private static final Pattern HTML_ENTITY_PATTERN = Pattern.compile("&(?!(?:[a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});)");
private String normalizedFiled(String inField) {
// When we encounter a '&' we check if it starts an HTML entity then we skip it, otherwise
// we should replace it with '&' to be rendered correctly.
return HTML_ENTITY_PATTERN.matcher(inField).replaceAll("&") // Replace & with & if it does not begin an HTML entity
.replaceAll("\\\\&", "&") // Replace \& with &
.replaceAll("[\\n]{2,}", "<p>") // Replace double line breaks with <p>
.replace("\n", "<br>") // Replace single line breaks with <br>
.replace("\\$", "$") // Replace \$ with $
.replaceAll("\\$([^$]*)\\$", "\\{$1\\}");
}Two "major" things:
- Refactor
HTMLCharsTestto use@ParamterizedTest. I think, with OpenAI, this is just an exercise how to use OpenAI ^^. -- That would also allow "easy" addition of the test covering the changed functionality. - A comment that Apache Common's escapeHtml4 is not a smart escaping and does not handle LaTeX characters adn commands
…preview' into some-characters-not-in-rendered-preview
Siedlerchr
approved these changes
Jan 23, 2024
Member
|
Thanks for the follow up! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #10677
TODO
Screenshots
Mandatory checks
CHANGELOG.mddescribed in a way that is understandable for the average user (if applicable)