HtmlUtils properly escapes single quotes as well
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -16,31 +16,36 @@
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Alef Arendsen
|
||||
* @author Martin Kersten
|
||||
* @author Rick Evans
|
||||
*/
|
||||
public class HtmlUtilsTests extends TestCase {
|
||||
public class HtmlUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testHtmlEscape() {
|
||||
String unescaped = "\"This is a quote";
|
||||
String unescaped = "\"This is a quote'";
|
||||
String escaped = HtmlUtils.htmlEscape(unescaped);
|
||||
assertEquals(""This is a quote", escaped);
|
||||
assertEquals(""This is a quote'", escaped);
|
||||
escaped = HtmlUtils.htmlEscapeDecimal(unescaped);
|
||||
assertEquals(""This is a quote", escaped);
|
||||
assertEquals(""This is a quote'", escaped);
|
||||
escaped = HtmlUtils.htmlEscapeHex(unescaped);
|
||||
assertEquals(""This is a quote", escaped);
|
||||
assertEquals(""This is a quote'", escaped);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHtmlUnescape() {
|
||||
String escaped = ""This is a quote";
|
||||
String escaped = ""This is a quote'";
|
||||
String unescaped = HtmlUtils.htmlUnescape(escaped);
|
||||
assertEquals(unescaped, "\"This is a quote");
|
||||
assertEquals(unescaped, "\"This is a quote'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeIntoHtmlCharacterSet() {
|
||||
assertNull("A null string should be converted to a null string",
|
||||
HtmlUtils.htmlEscape(null));
|
||||
@@ -66,6 +71,7 @@ public class HtmlUtilsTests extends TestCase {
|
||||
"ϑ", HtmlUtils.htmlEscapeDecimal("" + (char) 977));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeFromHtmlCharacterSet() {
|
||||
assertNull("A null string should be converted to a null string",
|
||||
HtmlUtils.htmlUnescape(null));
|
||||
|
||||
Reference in New Issue
Block a user