Fix another case of HTML leakage in snippets

* Add test for this case

Bug: 3285281
Change-Id: If45d33624ac5dbd16d28b45428be29e5a8c51046
This commit is contained in:
Marc Blank 2011-01-19 09:12:49 -08:00
parent 985155fddd
commit 0324017aa0
2 changed files with 4 additions and 3 deletions

View File

@ -45,8 +45,6 @@ public class Snippet {
static final String[] STRIP_TAGS = new String[] {"title ", "script", "style ", "applet"};
static final int STRIP_TAG_LENGTH = 6;
// Note: ESCAPE_STRINGS is taken from the StringUtil class which is part of the
// unbundled_google package
static final Map<String, Character> ESCAPE_STRINGS;
static {
// HTML character entity references as defined in HTML 4
@ -372,9 +370,10 @@ public class Snippet {
// Strip content of title, script, style and applet tags
if (i < (length - (STRIP_TAG_LENGTH + 2))) {
String tag = text.substring(i + 1, i + STRIP_TAG_LENGTH + 1);
String tagLowerCase = tag.toLowerCase();
boolean stripContent = false;
for (String stripTag: STRIP_TAGS) {
if (stripTag.equals(tag)) {
if (stripTag.equals(tagLowerCase)) {
stripContent = true;
break;
}

View File

@ -118,6 +118,8 @@ public class SnippetTests extends AndroidTestCase {
public void testStripContent() {
assertEquals("Visible", Snippet.fromHtmlText(
"<html><style foo=\"bar\">Not</style>Visible</html>"));
assertEquals("Visible", Snippet.fromHtmlText(
"<html><STYLE foo=\"bar\">Not</STYLE>Visible</html>"));
assertEquals("IsVisible", Snippet.fromHtmlText(
"<html><nostrip foo=\"bar\">Is</nostrip>Visible</html>"));
assertEquals("Visible", Snippet.fromHtmlText(