fix: correct HTML entity decoding in decode method and add tests for …#2542
fix: correct HTML entity decoding in decode method and add tests for …#2542
Conversation
Summary of ChangesHello @robfrank, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the HTML entity decoding logic, specifically ensuring that the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a bug where & was decoded to a space instead of &. The included tests effectively verify the fix and cover other HTML entities. My main feedback is on the decode method itself. While the fix is correct, the overall implementation of manually replacing entities is not robust or complete. I've suggested considering a dedicated library for HTML decoding to improve correctness and maintainability.
|
|
||
| protected String decode(final String command) { | ||
| return command.replace("&", " ").replace("<", "<").replace(">", ">").replace(""", "\"").replace("'", "'"); | ||
| return command.replace("&", "&").replace("<", "<").replace(">", ">").replace(""", "\"").replace("'", "'"); |
There was a problem hiding this comment.
While this change correctly fixes the decoding of &, the manual chain of replace() calls is not a robust solution for decoding HTML entities. It only handles a small, fixed set of entities and can be inefficient, as each replace() call potentially creates a new String object and scans the string from the beginning. A better approach would be to use a dedicated library, such as Apache Commons Text's StringEscapeUtils.unescapeHtml4(), which provides a comprehensive and optimized implementation. If adding a new dependency is not an option, consider a more efficient single-pass implementation using StringBuilder to avoid creating multiple intermediate strings.
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
b1ec304 to
e1d5a51
Compare
…JavaScript functions #2161
e1d5a51 to
70babd2
Compare
This pull request fixes a bug in the HTML entity decoding logic and adds new tests to ensure correctness. The main change corrects the decoding of the
&entity so that it is properly converted to&instead of a space. Additionally, new unit tests have been introduced to verify the decoding behavior for several HTML entities.Bug fix:
decodemethod inAbstractServerHttpHandler.javato correctly replace&with&instead of a space, ensuring logical operators and other ampersands are handled properly.Testing improvements:
PostCommandHandlerDecodeTest.javawith tests that verify the correct decoding of HTML entities, including&,<,>,", and'.