Skip to content

Commit e37292d

Browse files
jshields-squarespacemikesamuel
authored andcommitted
Add missing mappings for named HTML entities (#174)
* Add missing named HTML entity mappings * Get rid of chained method calls due to compiler resource utilization issues * Dynamically calculate longest entity name * Refactor map building to happen in static initializer * Add comment linking to source data * Make formatting consistent * Update Javadoc * Update Javadoc * Revert Javadoc changes * Update decodeEntityAt to return code-units instead of code-points * Update character literal * Update list of named character references using official spec * Simplify long to char conversion * Refactor decodeEntityAt to appendDecodedEntity * Remove unused imports * Add Nullable annotations * Add unit test to check boundary condition * Update comment
1 parent 7cdb5eb commit e37292d

File tree

5 files changed

+2213
-330
lines changed

5 files changed

+2213
-330
lines changed

src/main/java/org/owasp/html/CssTokens.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ private static int[] truncateOrShare(int[] arr, int limit) {
14421442
* See http://dev.w3.org/csswg/css-values/#lengths and
14431443
* http://dev.w3.org/csswg/css-values/#other-units
14441444
*/
1445-
private static final Trie UNIT_TRIE = new Trie(
1445+
private static final Trie<Integer> UNIT_TRIE = new Trie<Integer>(
14461446
ImmutableMap.<String, Integer>builder()
14471447
.put("em", LENGTH_UNIT_TYPE)
14481448
.put("ex", LENGTH_UNIT_TYPE)
@@ -1473,7 +1473,7 @@ private static int[] truncateOrShare(int[] arr, int limit) {
14731473

14741474
static boolean isWellKnownUnit(CharSequence s, int start, int end) {
14751475
if (start == end) { return false; }
1476-
Trie t = UNIT_TRIE;
1476+
Trie<Integer> t = UNIT_TRIE;
14771477
for (int i = start; i < end; ++i) {
14781478
char ch = s.charAt(i);
14791479
t = t.lookup('A' <= ch && ch <= 'Z' ? (char) (ch | 32) : ch);

src/main/java/org/owasp/html/Encoding.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ public static String decodeHtml(String s) {
5454
int pos = 0;
5555
int amp = firstAmp;
5656
while (amp >= 0) {
57-
long endAndCodepoint = HtmlEntities.decodeEntityAt(s, amp, n);
58-
int end = (int) (endAndCodepoint >>> 32);
59-
int codepoint = (int) endAndCodepoint;
60-
sb.append(s, pos, amp).appendCodePoint(codepoint);
57+
sb.append(s, pos, amp);
58+
int end = HtmlEntities.appendDecodedEntity(s, amp, n, sb);
6159
pos = end;
6260
amp = s.indexOf('&', end);
6361
}

0 commit comments

Comments
 (0)