GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix HtmlUtils unescape for supplementary chars by juntae6942 · Pull Request #35477 · spring-projects/spring-framework

Conversation

@juntae6942

@juntae6942 juntae6942 commented Sep 13, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Closes: #35426

Currently, HtmlUtils.htmlUnescape() does not correctly handle numeric character references for Unicode supplementary characters (e.g., emojis).

For example, an entity like 😀 (😀) is incorrectly converted to a garbled character corresponding to U+F600 due to data truncation.

Step to Reproduce

public static void main(String[] args) {
        // Test character: 'Grinning Face' emoji (😀)
        // Unicode code point: U+1F600
        // Hexadecimal: 1F600
        // Decimal: 128512

        // 1. Input value as a decimal HTML entity
        String inputDecimal = "😀";

        // 2. Input value as a hexadecimal HTML entity
        String inputHex = "😀";

        // 3. The expected result after correct conversion
        String expectedOutput = "😀";

        System.out.println("--- Decimal HTML Entity Test ---");
        System.out.println("Input: " + inputDecimal);

        // Call the HtmlUtils.htmlUnescape() method
        String actualOutputDecimal = HtmlUtils.htmlUnescape(inputDecimal);

        System.out.println("Actual Output: " + actualOutputDecimal);
        System.out.println("Expected Output: " + expectedOutput);
        System.out.println("Result matches expected: " + expectedOutput.equals(actualOutputDecimal));

        System.out.println("\n--- Hexadecimal HTML Entity Test ---");
        System.out.println("Input: " + inputHex);

        // Call the HtmlUtils.htmlUnescape() method
        String actualOutputHex = HtmlUtils.htmlUnescape(inputHex);

        System.out.println("Actual Output: " + actualOutputHex);
        System.out.println("Expected Output: " + expectedOutput);
        System.out.println("Result matches expected: " + expectedOutput.equals(actualOutputHex));
    }
스크린샷 2025-09-13 오후 11 29 37

Cause

The root cause was a problematic cast to a 16-bit char in the HtmlCharacterEntityDecoder. This operation truncated any Unicode code point value greater than U+FFFF, leading to the loss of the most significant bits.

Solution

This PR resolves the issue by replacing the direct (char) cast with a call to StringBuilder.appendCodePoint().

The appendCodePoint() method is designed to handle the full range of Unicode code points. It correctly converts supplementary characters into a two-character surrogate pair, ensuring that all characters are unescaped without data loss. A corresponding unit test has been added to verify this fix.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

injae-kim reacted with thumbs up emoji injae-kim reacted with heart emoji injae-kim reacted with rocket emoji
All reactions
  • 👍 1 reaction
  • ❤️ 1 reaction
  • 🚀 1 reaction
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 13, 2025
@juntae6942 juntae6942 mentioned this pull request Sep 13, 2025
HtmlUtils.htmlUnescape() incorrect for numeric character references >= 𐀀 / 𐀀 #35426
Closed
@juntae6942
Fix HtmlUtils unescape for supplementary chars
0b60800
Signed-off-by: potato <[email protected]>
@juntae6942
juntae6942 force-pushed the fix/spring-framework-35426-htmlunescape-unicode branch from bc095df to 369ffe4 Compare September 14, 2025 04:41
@juntae6942
Test: Add case for basic HTML entities in HtmlUtils
a6efa2a
Signed-off-by: potato <[email protected]>
@juntae6942
juntae6942 force-pushed the fix/spring-framework-35426-htmlunescape-unicode branch from 369ffe4 to a6efa2a Compare September 14, 2025 04:48
@juntae6942
Style: Format code to align with project conventions
7378478
Signed-off-by: potato <[email protected]>
@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Nov 4, 2025
@bclozel bclozel self-assigned this Nov 17, 2025
@bclozel bclozel added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 17, 2025
@bclozel bclozel added this to the 7.0.1 milestone Nov 17, 2025
@bclozel bclozel added for: backport-to-7.0.x Marks an issue as a candidate for backport to 7.0.x and removed for: backport-to-7.0.x Marks an issue as a candidate for backport to 7.0.x labels Nov 17, 2025
bclozel pushed a commit that referenced this pull request Nov 17, 2025
@juntae6942 @bclozel
Fix HtmlUtils unescape for supplementary chars
47de8b0
See gh-35477

Signed-off-by: potato <[email protected]>
@bclozel bclozel closed this in 87d95dc Nov 17, 2025
bclozel pushed a commit that referenced this pull request Nov 17, 2025
@juntae6942 @bclozel
Fix HtmlUtils unescape for supplementary chars
5af1c9b
See gh-35477

Signed-off-by: potato <[email protected]>
bclozel added a commit that referenced this pull request Nov 17, 2025
@bclozel
Polishing contribution
030dace
Closes gh-35477
@github-actions github-actions Bot added the status: backported An issue that has been backported to maintenance branches label Nov 17, 2025
@github-actions github-actions Bot mentioned this pull request Nov 17, 2025
Fix HtmlUtils unescape for supplementary chars #35832
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@bclozel bclozel

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug

Projects

None yet

Milestone

7.0.1

Development

Successfully merging this pull request may close these issues.

HtmlUtils.htmlUnescape() incorrect for numeric character references >= &#x10000; / &#65536;

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@juntae6942 @bclozel @rstoyanchev @spring-projects-issues
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.