You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2010/02/10 16:17:59 UTC
svn commit: r908533 - in /incubator/wookie/trunk:
src-tests/org/apache/wookie/tests/HtmlCleanerTest.java
src/org/apache/wookie/util/html/HtmlCleaner.java
Author: scottbw
Date: Wed Feb 10 15:17:58 2010
New Revision: 908533
URL: http://svn.apache.org/viewvc?rev=908533&view=rev
Log:
Adds all scripts to the user scripts collection when parsing the page, not just those with a src attribute; this addresses issue WOOKIE-113. Also added a testcase for it.
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/HtmlCleanerTest.java
incubator/wookie/trunk/src/org/apache/wookie/util/html/HtmlCleaner.java
Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/HtmlCleanerTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/HtmlCleanerTest.java?rev=908533&r1=908532&r2=908533&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/HtmlCleanerTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/HtmlCleanerTest.java Wed Feb 10 15:17:58 2010
@@ -67,6 +67,26 @@
fail();
}
}
+
+ /**
+ * tests that user scripts are placed after injected scripts and are not reordered
+ */
+ @Test
+ public void injectScriptWithUserScriptNoReorder(){
+ HtmlCleaner cleaner = new HtmlCleaner();
+ String content = "<head><script type=\"text/javascript\" src=\"user.js\"></script><script type=\"text/javascript\">google.load(\"dojo\", \"1.4.1\");</script></head>";
+ String out = "";
+ StringWriter writer = new StringWriter();
+ try {
+ cleaner.setReader(new StringReader(content));
+ cleaner.injectScript("inject.js");
+ cleaner.process(writer);
+ out = writer.getBuffer().toString();
+ assertEquals("<html><head><script type=\"text/javascript\" src=\"inject.js\"></script><script type=\"text/javascript\" src=\"user.js\"></script><script type=\"text/javascript\">google.load(\"dojo\", \"1.4.1\");</script></head><body></body></html>", out);
+ } catch (IOException e) {
+ fail();
+ }
+ }
/**
* tests injecting stylesheet
Modified: incubator/wookie/trunk/src/org/apache/wookie/util/html/HtmlCleaner.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/html/HtmlCleaner.java?rev=908533&r1=908532&r2=908533&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/html/HtmlCleaner.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/html/HtmlCleaner.java Wed Feb 10 15:17:58 2010
@@ -127,7 +127,7 @@
private void getUserScripts(){
List<TagNode> children = headNode.getChildren();
for(TagNode child : children){
- if(child.getName().equals(SCRIPT_TAG) && child.getAttributeByName(SRC_ATTRIBUTE)!=null){
+ if(child.getName().equals(SCRIPT_TAG)){
scriptList.add(child);
}
}