modules/enterprise/server/plugins/jboss-software/src/main/java/org/rhq/enterprise/server/plugins/jboss/software/HtmlUtility.java
| 22 ++++++++--
modules/enterprise/server/plugins/jboss-software/src/test/java/org/rhq/enterprise/server/plugins/jboss/software/HtmlUtilityTest.java
| 15 ++++++
2 files changed, 33 insertions(+), 4 deletions(-)
New commits:
commit 6345fd47ccfd12a3729d773f64b07f4613e64ede
Author: Ian P. Springer <ips(a)jetengine.(none)>
Date: Thu Mar 25 11:31:48 2010 -0400
add unit test and bug fix for HtmlUtility.unescapeHtml()
diff --git
a/modules/enterprise/server/plugins/jboss-software/src/main/java/org/rhq/enterprise/server/plugins/jboss/software/HtmlUtility.java
b/modules/enterprise/server/plugins/jboss-software/src/main/java/org/rhq/enterprise/server/plugins/jboss/software/HtmlUtility.java
index b3ae50a..bc1ec97 100644
---
a/modules/enterprise/server/plugins/jboss-software/src/main/java/org/rhq/enterprise/server/plugins/jboss/software/HtmlUtility.java
+++
b/modules/enterprise/server/plugins/jboss-software/src/main/java/org/rhq/enterprise/server/plugins/jboss/software/HtmlUtility.java
@@ -72,18 +72,22 @@ public class HtmlUtility {
if (ampersandIndex >= 0 && ampersandIndex < (string.length() -
3)) {
int semicolonIndex = string.indexOf(";", ampersandIndex + 1);
if (semicolonIndex >= 0) {
- // Found an entity - see if it's one we grok.
+ // Found an entity.
+
+ // Append the substring from the index up to but not including the
ampersand.
+ unescapedString.append(string.substring(index, ampersandIndex));
+
String entity = string.substring(ampersandIndex, semicolonIndex +
1);
+ // See if the entity is one we grok.
Character c = ENTITY_TO_CHAR_MAP.get(entity);
if (c != null) {
- // If we were able to map the entity, append the unescaped
character.
+ // If we were able to map the entity to a character, append the
character.
unescapedString.append(c);
} else {
// Otherwise, append the unknown entity as is.
unescapedString.append(entity);
}
- // Append the substring from the index up to but not including the
ampersand.
- unescapedString.append(string.substring(index, ampersandIndex));
+
index = semicolonIndex + 1;
} else {
// No semicolon found - not an entity. Append the substring from the
index up to and including the
@@ -100,4 +104,14 @@ public class HtmlUtility {
return unescapedString.toString();
}
+
+ public static void main(String[] args) {
+ if (args.length != 1) {
+ System.err.println("Usage: java " + HtmlUtility.class.getName() +
" html");
+ System.exit(1);
+ }
+ String html = args[0];
+ String unescapedHtml = unescapeHTML(html);
+ System.out.println(unescapedHtml);
+ }
}
diff --git
a/modules/enterprise/server/plugins/jboss-software/src/test/java/org/rhq/enterprise/server/plugins/jboss/software/HtmlUtilityTest.java
b/modules/enterprise/server/plugins/jboss-software/src/test/java/org/rhq/enterprise/server/plugins/jboss/software/HtmlUtilityTest.java
new file mode 100644
index 0000000..5333080
--- /dev/null
+++
b/modules/enterprise/server/plugins/jboss-software/src/test/java/org/rhq/enterprise/server/plugins/jboss/software/HtmlUtilityTest.java
@@ -0,0 +1,15 @@
+package org.rhq.enterprise.server.plugins.jboss.software;
+
+import org.testng.annotations.Test;
+
+/**
+ * @author Ian Springer
+ */
+public class HtmlUtilityTest {
+ @Test
+ public void testUnescapeHTML() throws Exception {
+ String result = HtmlUtility.unescapeHTML("
<html>\nblah \n</html>&foo&bleh;");
+ System.out.println("result=[" + result + "]");
+ assert result.equals(" <html>\nblah
\n</html>&foo&bleh;");
+ }
+}
Show replies by date