mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-28 14:52:24 +00:00
SEC-812: Added missing TextUtils file
This commit is contained in:
parent
fa44c74993
commit
fca3a2a709
@ -0,0 +1,33 @@
|
|||||||
|
package org.springframework.security.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities for working with Strings and text.
|
||||||
|
*
|
||||||
|
* @author Luke Taylor
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public abstract class TextUtils {
|
||||||
|
|
||||||
|
public static String escapeEntities(String s) {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
|
for (int i=0; i < s.length(); i++) {
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if(c == '<') {
|
||||||
|
sb.append("<");
|
||||||
|
} else if (c == '>') {
|
||||||
|
sb.append(">");
|
||||||
|
} else if (c == '"') {
|
||||||
|
sb.append(""");
|
||||||
|
} else if (c == '\'') {
|
||||||
|
sb.append("'");
|
||||||
|
} else {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package org.springframework.security.util;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TextUtilsTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void charactersAreEscapedCorrectly() {
|
||||||
|
assertEquals("a<script>"'", TextUtils.escapeEntities("a<script>\"'"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user