Skip to content

Fix mangled text after JSoup parsing - #5645

Merged
cwisniew merged 4 commits into
RPTools:release-1.18from
kwvanderlinde:bugfix/5640-jsoup-entities
Jun 27, 2025
Merged

Fix mangled text after JSoup parsing#5645
cwisniew merged 4 commits into
RPTools:release-1.18from
kwvanderlinde:bugfix/5640-jsoup-entities

Conversation

@kwvanderlinde

@kwvanderlinde kwvanderlinde commented Jun 26, 2025

Copy link
Copy Markdown
Collaborator

Identify the Bug or Feature request

Fixes #5640

Description of the Change

The key change here is that the document output settings are now set to output ASCII text only. Any non-ASCII characters, including characters from resolved references - such as for • - will be replaced by entities (not necessarily the same entity, but an equivalent one).

To make sure we don't end up in a situation where some code paths result in ASCII, while others keep the unicode characters, I've modifed HTMLContent to always parse HTML documents, and to represent them as Document objects instead of raw strings. When the string is needed, Document#html() will render it to a string, applying the output settings described above.

As we're now guaranteed to have ASCII HTML documents, the base64 data: URL workaround from #5442 is no longer needed and has been removed.

And since I was in the weeds here anyways, I removed the unused bits of HTMLContent, encapsulated it more by making some public stuff private, and changed Content from a single record class representing many types to an ADT that represents each type as its own record class.

Possible Drawbacks

The HTML content of frames and dialogs will not match the code provided by the macro author. This was already true, but now it's extra true. Although the result should be functionally equivalent, it may cause confusion if the loaded HTML source is ever viewed.

Documentation Notes

N/A

Release Notes

  • Fixed a bug where HTML entities for non-ascii characters would not render correctly in frame5, dialog5 or overlay.

This change is Reviewable

- Remove unused bits
- Privatize things that don't need to be public
- HTMLContent.content can actually be non-null
- Inline injectJavaBridgeAndBaseUrl(null) into injectJavaBridge()
- Inline injectUrlBase(String, URL) into injectUrlBase(URL)
Each content type is now represented by its own record class that contains only those fields it supports.
This ensures that the same conversions apply regardless of whether we happened to call injectJavaBridge() or similar.
Also means we don't need to convert HTML5 documents to a base64 `data:` url since the content won't contain surrogate
pairs.
@kwvanderlinde kwvanderlinde self-assigned this Jun 26, 2025
@kwvanderlinde kwvanderlinde moved this from Todo to Awaiting-Review in MapTool 1.18 Jun 26, 2025
@github-actions github-actions Bot added the bug label Jun 26, 2025
@github-project-automation github-project-automation Bot moved this from Awaiting-Review to To-Be-Merged in MapTool 1.18 Jun 27, 2025
@cwisniew
cwisniew merged commit e602917 into RPTools:release-1.18 Jun 27, 2025
@github-project-automation github-project-automation Bot moved this from To-Be-Merged to Merged in MapTool 1.18 Jun 27, 2025
@kwvanderlinde
kwvanderlinde deleted the bugfix/5640-jsoup-entities branch June 27, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

2 participants