-
Notifications
You must be signed in to change notification settings - Fork 54
HtmlHelper.toPlainText: correctly decode character references #1604
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
Open
bschwarzent
wants to merge
1
commit into
releases/25.2
Choose a base branch
from
features/bsh/25.2/413114_html_entities
base: releases/25.2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
132 changes: 132 additions & 0 deletions
132
...t.rt.platform.test/src/test/java/org/eclipse/scout/rt/platform/html/HtmlEntitiesTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| * Copyright (c) 2010, 2025 BSI Business Systems Integration AG | ||
| * | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package org.eclipse.scout.rt.platform.html; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import org.eclipse.scout.rt.platform.BEANS; | ||
| import org.eclipse.scout.rt.testing.platform.runner.PlatformTestRunner; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| @SuppressWarnings({"ConcatenationWithEmptyString", "SpellCheckingInspection", "TextBlockMigration"}) | ||
| @RunWith(PlatformTestRunner.class) | ||
| public class HtmlEntitiesTest { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may add some of these tests to ts spec? (plain text encoder should do same transformations) |
||
|
|
||
| @Test | ||
| public void testUnescapeAll_Empty() { | ||
| final HtmlEntities entities = BEANS.get(HtmlEntities.class); | ||
| assertNull(entities.unescapeAll(null)); | ||
| assertEquals("", entities.unescapeAll("")); | ||
| assertEquals(" ", entities.unescapeAll(" ")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUnescapeAll_Named() { | ||
| final HtmlEntities entities = BEANS.get(HtmlEntities.class); | ||
| assertEquals("ß", entities.unescapeAll("ß")); | ||
| assertEquals("Ü", entities.unescapeAll("Ü")); | ||
| assertEquals("&", entities.unescapeAll("&")); | ||
| assertEquals("A&&Z", entities.unescapeAll("A&&Z")); | ||
| assertEquals("ä", entities.unescapeAll("ä")); | ||
| assertEquals("auml;", entities.unescapeAll("auml;")); | ||
| assertEquals("drag&drop", entities.unescapeAll("drag&drop")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUnescapeAll_NumericDecimal() { | ||
| final HtmlEntities entities = BEANS.get(HtmlEntities.class); | ||
| assertEquals("'", entities.unescapeAll("'")); | ||
| assertEquals("€", entities.unescapeAll("€")); | ||
| assertEquals("A€€Z", entities.unescapeAll("A€€Z")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUnescapeAll_NumericHex() { | ||
| final HtmlEntities entities = BEANS.get(HtmlEntities.class); | ||
| assertEquals("B", entities.unescapeAll("B")); | ||
| assertEquals("B", entities.unescapeAll("B")); | ||
| assertEquals("?", entities.unescapeAll("?")); | ||
| assertEquals("?", entities.unescapeAll("?")); | ||
| assertEquals("🦕", entities.unescapeAll("🦕")); | ||
| assertEquals("A🦕🦕Z", entities.unescapeAll("A🦕🦕Z")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUnescapeAll_ComplexStrings() { | ||
| final HtmlEntities entities = BEANS.get(HtmlEntities.class); | ||
| assertEquals("text'text", entities.unescapeAll("text'text")); | ||
| assertEquals("'€", entities.unescapeAll("'€")); | ||
| assertEquals("/ˈʊmlaʊt/", entities.unescapeAll("/ˈʊmlaʊt/")); | ||
| assertEquals("Kühlflüssigkeitsüberlaufbehälter", entities.unescapeAll("Kühlflüssigkeitsüberlaufbehälter")); | ||
| assertEquals(" [Viele Kühe machen Mühe!] ", entities.unescapeAll(" [Viele Kühe machen Mühe!] ")); | ||
| assertEquals("🤸🏾♀️", entities.unescapeAll("🤸🏾‍♀️")); | ||
| assertEquals("🏴☠️", entities.unescapeAll("🏴‍☠️")); | ||
| assertEquals("" | ||
| + "Face with Tears of Joy Emoji: \uD83D\uDE02\n" | ||
| + "Party Popper Emoji: \uD83C\uDF89\n" | ||
| + "Man Technologist: Medium-light Skin Tone: \uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDCBB", | ||
| entities.unescapeAll("" | ||
| + "Face with Tears of Joy Emoji: 😂\n" | ||
| + "Party Popper Emoji: 🎉\n" | ||
| + "Man Technologist: Medium-light Skin Tone: 👨🏼‍💻")); | ||
| assertEquals("<body><div data-value=\"¡Hola!\">Zürich</div><hr></body>", entities.unescapeAll("<body><div data-value=\"¡Hola!\">Zürich</div><hr></body>")); | ||
| assertEquals("Qu’est-ce que c’est?", entities.unescapeAll("Qu’est-ce que c’est?")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUnescapeAll_Invalid() { | ||
| final HtmlEntities entities = BEANS.get(HtmlEntities.class); | ||
| assertEquals("ä &doesNotExist; é", entities.unescapeAll("ä &doesNotExist; é")); // invalid entity name | ||
| assertEquals("a   b", entities.unescapeAll("a   b")); // not terminated by ';' | ||
| assertEquals("drag&drop", entities.unescapeAll("drag&drop")); // not an entity name | ||
| assertEquals("drag & drop", entities.unescapeAll("drag & drop")); // not an entity name | ||
| assertEquals("& auml;", entities.unescapeAll("& auml;")); // space after '&' | ||
| assertEquals("ä ;", entities.unescapeAll("ä ;")); // space before ';' | ||
| assertEquals("ä,", entities.unescapeAll("ä,")); // not terminated by ';' | ||
| assertEquals("�", entities.unescapeAll("�")); // not a valid code point | ||
| assertEquals("&39;", entities.unescapeAll("&39;")); // missing '#' | ||
| assertEquals("&#a0;", entities.unescapeAll("&#a0;")); // missing 'x' | ||
| } | ||
|
|
||
| @Test | ||
| public void testDecodeNamedCharacterReference() { | ||
| final HtmlEntities entities = BEANS.get(HtmlEntities.class); | ||
|
|
||
| assertEquals("ä", entities.decodeNamedCharacterReference("ä")); | ||
| assertEquals("'", entities.decodeNamedCharacterReference("'")); | ||
|
|
||
| assertNull(entities.decodeNamedCharacterReference(null)); | ||
| assertNull(entities.decodeNamedCharacterReference("")); | ||
| assertNull(entities.decodeNamedCharacterReference("&doesNotExist;")); | ||
| assertNull(entities.decodeNamedCharacterReference("äü")); | ||
| assertNull(entities.decodeNamedCharacterReference("auml")); | ||
| assertNull(entities.decodeNamedCharacterReference("'")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDecodeNumericCharacterReference() { | ||
| final HtmlEntities entities = BEANS.get(HtmlEntities.class); | ||
|
|
||
| assertEquals("ä", entities.decodeNumericCharacterReference("ä")); | ||
| assertEquals("ä", entities.decodeNumericCharacterReference("ä")); | ||
| assertEquals("'", entities.decodeNumericCharacterReference("'")); | ||
| assertEquals("'", entities.decodeNumericCharacterReference("'")); | ||
|
|
||
| assertNull(entities.decodeNumericCharacterReference(null)); | ||
| assertNull(entities.decodeNumericCharacterReference("")); | ||
| assertNull(entities.decodeNumericCharacterReference("&doesNotExist;")); | ||
| assertNull(entities.decodeNumericCharacterReference("ä'")); | ||
| assertNull(entities.decodeNumericCharacterReference("#39;")); | ||
| assertNull(entities.decodeNumericCharacterReference("&#E4;")); | ||
| assertNull(entities.decodeNumericCharacterReference("&#hello;")); | ||
| assertNull(entities.decodeNumericCharacterReference("�")); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these special spaces? in this case may add a comment? otherwise I would expect that duplicated spaces are deleted..