Merge "Strip content of the "head" tag" into honeycomb
This commit is contained in:
commit
6c9911e3fb
@ -42,7 +42,9 @@ public class Snippet {
|
||||
/*package*/ static final char NON_BREAKING_SPACE_CHARACTER = (char)160;
|
||||
|
||||
// Tags whose content must be stripped as well
|
||||
static final String[] STRIP_TAGS = new String[] {"title ", "script", "style ", "applet"};
|
||||
static final String[] STRIP_TAGS =
|
||||
new String[] {"title", "script", "style", "applet", "head"};
|
||||
// The number of characters we peel off for testing against STRIP_TAGS
|
||||
static final int STRIP_TAG_LENGTH = 6;
|
||||
|
||||
static final Map<String, Character> ESCAPE_STRINGS;
|
||||
@ -373,8 +375,9 @@ public class Snippet {
|
||||
String tagLowerCase = tag.toLowerCase();
|
||||
boolean stripContent = false;
|
||||
for (String stripTag: STRIP_TAGS) {
|
||||
if (stripTag.equals(tagLowerCase)) {
|
||||
if (tagLowerCase.startsWith(stripTag)) {
|
||||
stripContent = true;
|
||||
tag = tag.substring(0, stripTag.length());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -128,6 +128,8 @@ public class SnippetTests extends AndroidTestCase {
|
||||
"<html>Visible<style foo=\"bar\">Not</style>AgainVisible"));
|
||||
assertEquals("VisibleAgainVisible", Snippet.fromHtmlText(
|
||||
"<html>Visible<style foo=\"bar\"/>AgainVisible"));
|
||||
assertEquals("VisibleAgainVisible", Snippet.fromHtmlText(
|
||||
"<html>Visible<style foo=\"bar\"/><head><//blah<style>Not</head>AgainVisible"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,4 +160,22 @@ public class SnippetTests extends AndroidTestCase {
|
||||
// Test with space at end of tag
|
||||
findTagEnd("<tag foo=\"bar\">some more text but no end tag", "tag ");
|
||||
}
|
||||
|
||||
// For debugging large HTML samples
|
||||
|
||||
// private String readLargeSnippet(String fn) {
|
||||
// File file = mContext.getFileStreamPath(fn);
|
||||
// StringBuffer sb = new StringBuffer();
|
||||
// BufferedReader reader = null;
|
||||
// try {
|
||||
// String text;
|
||||
// reader = new BufferedReader(new FileReader(file));
|
||||
// while ((text = reader.readLine()) != null) {
|
||||
// sb.append(text);
|
||||
// sb.append(" ");
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
// return sb.toString();
|
||||
// }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user