|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -19,18 +19,19 @@ package org.springframework.web.util;
@@ -19,18 +19,19 @@ package org.springframework.web.util;
|
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Utility class for HTML escaping. Escapes and unescapes |
|
|
|
|
* based on the W3C HTML 4.01 recommendation, handling |
|
|
|
|
* Utility class for HTML escaping. |
|
|
|
|
* |
|
|
|
|
* <p>Escapes and unescapes based on the W3C HTML 4.01 recommendation, handling |
|
|
|
|
* character entity references. |
|
|
|
|
* |
|
|
|
|
* <p>Reference: |
|
|
|
|
* <a href="https://www.w3.org/TR/html4/charset.html">https://www.w3.org/TR/html4/charset.html</a>
|
|
|
|
|
* |
|
|
|
|
* <p>For a comprehensive set of String escaping utilities, |
|
|
|
|
* consider Apache Commons Lang and its StringEscapeUtils class. |
|
|
|
|
* We are not using that class here to avoid a runtime dependency |
|
|
|
|
* on Commons Lang just for HTML escaping. Furthermore, Spring's |
|
|
|
|
* HTML escaping is more flexible and 100% HTML 4.0 compliant. |
|
|
|
|
* <p>For a comprehensive set of String escaping utilities, consider |
|
|
|
|
* <a href="https://commons.apache.org/proper/commons-text/">Apache Commons Text</a> |
|
|
|
|
* and its {@code StringEscapeUtils} class. We do not use that class here in order |
|
|
|
|
* to avoid a runtime dependency on Commons Text just for HTML escaping. Furthermore, |
|
|
|
|
* Spring's HTML escaping is more flexible and 100% HTML 4.0 compliant. |
|
|
|
|
* |
|
|
|
|
* @author Juergen Hoeller |
|
|
|
|
* @author Martin Kersten |
|
|
|
|
@ -48,7 +49,7 @@ public abstract class HtmlUtils {
@@ -48,7 +49,7 @@ public abstract class HtmlUtils {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Turn special characters into HTML character references. |
|
|
|
|
* Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Escapes all special characters to their corresponding |
|
|
|
|
* entity reference (e.g. {@code <}). |
|
|
|
|
* <p>Reference: |
|
|
|
|
@ -64,7 +65,7 @@ public abstract class HtmlUtils {
@@ -64,7 +65,7 @@ public abstract class HtmlUtils {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Turn special characters into HTML character references. |
|
|
|
|
* Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Escapes all special characters to their corresponding |
|
|
|
|
* entity reference (e.g. {@code <}) at least as required by the |
|
|
|
|
* specified encoding. In other words, if a special character does |
|
|
|
|
@ -97,7 +98,7 @@ public abstract class HtmlUtils {
@@ -97,7 +98,7 @@ public abstract class HtmlUtils {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Turn special characters into HTML character references. |
|
|
|
|
* Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Escapes all special characters to their corresponding numeric |
|
|
|
|
* reference in decimal format (&#<i>Decimal</i>;). |
|
|
|
|
* <p>Reference: |
|
|
|
|
@ -113,7 +114,7 @@ public abstract class HtmlUtils {
@@ -113,7 +114,7 @@ public abstract class HtmlUtils {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Turn special characters into HTML character references. |
|
|
|
|
* Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Escapes all special characters to their corresponding numeric |
|
|
|
|
* reference in decimal format (&#<i>Decimal</i>;) at least as required by the |
|
|
|
|
* specified encoding. In other words, if a special character does |
|
|
|
|
@ -147,7 +148,7 @@ public abstract class HtmlUtils {
@@ -147,7 +148,7 @@ public abstract class HtmlUtils {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Turn special characters into HTML character references. |
|
|
|
|
* Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Escapes all special characters to their corresponding numeric |
|
|
|
|
* reference in hex format (&#x<i>Hex</i>;). |
|
|
|
|
* <p>Reference: |
|
|
|
|
@ -163,7 +164,7 @@ public abstract class HtmlUtils {
@@ -163,7 +164,7 @@ public abstract class HtmlUtils {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Turn special characters into HTML character references. |
|
|
|
|
* Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Handles complete character set defined in HTML 4.01 recommendation. |
|
|
|
|
* <p>Escapes all special characters to their corresponding numeric |
|
|
|
|
* reference in hex format (&#x<i>Hex</i>;) at least as required by the |
|
|
|
|
* specified encoding. In other words, if a special character does |
|
|
|
|
@ -205,8 +206,8 @@ public abstract class HtmlUtils {
@@ -205,8 +206,8 @@ public abstract class HtmlUtils {
|
|
|
|
|
* &#<i>Decimal</i>; - <i>(Example: &#68;)</i><br> |
|
|
|
|
* &#x<i>Hex</i>; - <i>(Example: &#xE5;) case insensitive</i><br> |
|
|
|
|
* </blockquote> |
|
|
|
|
* Gracefully handles malformed character references by copying original |
|
|
|
|
* characters as is when encountered.<p> |
|
|
|
|
* <p>Gracefully handles malformed character references by copying original |
|
|
|
|
* characters as is when encountered. |
|
|
|
|
* <p>Reference: |
|
|
|
|
* <a href="https://www.w3.org/TR/html4/sgml/entities.html"> |
|
|
|
|
* https://www.w3.org/TR/html4/sgml/entities.html
|
|
|
|
|
|