Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian de Alwis2016-03-10 22:02:37 +0000
committerBrian de Alwis2016-11-21 17:06:23 +0000
commita5b2e9430aa6276fd39d33b3b337c0e2520859e3 (patch)
tree3ab0465ca67e9625717e9d938ba01b11e0c9c6d2
parent47dca3655d8d8228703066e63ee7e8c25b731a9a (diff)
downloadeclipse.platform.ua-I20161205-0800.tar.gz
eclipse.platform.ua-I20161205-0800.tar.xz
eclipse.platform.ua-I20161205-0800.zip
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/AboutParser.java4
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/NavParser.java4
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/ParseElement.java8
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/ResultParser.java6
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/utils/JSonHelper.java12
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java3
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/JsonHelperTests.java17
7 files changed, 39 insertions, 15 deletions
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/AboutParser.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/AboutParser.java
index d0c21f958..d24570b07 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/AboutParser.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/AboutParser.java
@@ -102,13 +102,13 @@ public class AboutParser extends ResultParser {
buf.append(JSonHelper.BEGIN_BRACE);
buf.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
- buf.append(JSonHelper.IDENTIFIER);
+ buf.append(JSonHelper.getQuotes(JSonHelper.IDENTIFIER));
buf.append(JSonHelper.COLON);
buf.append(JSonHelper.getQuotes(id));
buf.append(JSonHelper.COMMA);
buf.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
- buf.append(JSonHelper.LABEL);
+ buf.append(JSonHelper.getQuotes(JSonHelper.LABEL));
buf.append(JSonHelper.COLON);
buf.append(JSonHelper.getQuotes(label));
buf.append(JSonHelper.COMMA);
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/NavParser.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/NavParser.java
index 0dcab04e8..c1446fa65 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/NavParser.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/NavParser.java
@@ -60,13 +60,13 @@ public class NavParser extends ResultParser {
buf.append(JSonHelper.BEGIN_BRACE);
buf.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
- buf.append(JSonHelper.IDENTIFIER);
+ buf.append(JSonHelper.getQuotes(JSonHelper.IDENTIFIER));
buf.append(JSonHelper.COLON);
buf.append(JSonHelper.getQuotes(id));
buf.append(JSonHelper.COMMA);
buf.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
- buf.append(JSonHelper.LABEL);
+ buf.append(JSonHelper.getQuotes(JSonHelper.LABEL));
buf.append(JSonHelper.COLON);
buf.append(JSonHelper.getQuotes(label));
buf.append(JSonHelper.COMMA);
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/ParseElement.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/ParseElement.java
index 2e72fca8b..909d3839a 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/ParseElement.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/ParseElement.java
@@ -82,7 +82,7 @@ public class ParseElement {
String val = props.getProperty(key);
buff.append(JSonHelper.NEWLINE + space + JSonHelper.SPACE);
- buff.append(key);
+ buff.append(JSonHelper.getQuotes(key));
buff.append(JSonHelper.COLON);
try {
val = URLEncoder.encode(val, "UTF-8"); //$NON-NLS-1$
@@ -105,7 +105,7 @@ public class ParseElement {
} else {
buff.append(JSonHelper.NEWLINE + space + JSonHelper.SPACE);
- buff.append(JSonHelper.CHILDREN);
+ buff.append(JSonHelper.getQuotes(JSonHelper.CHILDREN));
buff.append(JSonHelper.COLON);
buff.append(JSonHelper.BEGIN_BRACKET);
@@ -141,7 +141,7 @@ public class ParseElement {
String val = props.getProperty(key);
buff.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
- buff.append(key);
+ buff.append(JSonHelper.getQuotes(key));
buff.append(JSonHelper.COLON);
try {
val = URLEncoder.encode(val, "UTF-8"); //$NON-NLS-1$
@@ -164,7 +164,7 @@ public class ParseElement {
} else {
buff.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
- buff.append(JSonHelper.ITEMS);
+ buff.append(JSonHelper.getQuotes(JSonHelper.ITEMS));
buff.append(JSonHelper.COLON);
buff.append(JSonHelper.BEGIN_BRACKET);
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/ResultParser.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/ResultParser.java
index 48c905c6d..cd3829553 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/ResultParser.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/parser/ResultParser.java
@@ -77,19 +77,19 @@ public class ResultParser extends DefaultHandler {
buf.append(JSonHelper.BEGIN_BRACE);
buf.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
- buf.append(JSonHelper.IDENTIFIER);
+ buf.append(JSonHelper.getQuotes(JSonHelper.IDENTIFIER));
buf.append(JSonHelper.COLON);
buf.append(JSonHelper.getQuotes(id));
buf.append(JSonHelper.COMMA);
buf.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
- buf.append(JSonHelper.LABEL);
+ buf.append(JSonHelper.getQuotes(JSonHelper.LABEL));
buf.append(JSonHelper.COLON);
buf.append(JSonHelper.getQuotes(label));
buf.append(JSonHelper.COMMA);
buf.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
- buf.append(JSonHelper.ITEMS);
+ buf.append(JSonHelper.getQuotes(JSonHelper.ITEMS));
buf.append(JSonHelper.COLON);
buf.append(JSonHelper.BEGIN_BRACKET);
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/utils/JSonHelper.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/utils/JSonHelper.java
index 225573048..1043d559f 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/utils/JSonHelper.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/utils/JSonHelper.java
@@ -15,7 +15,7 @@ public final class JSonHelper {
//JSON Characters
public static final String BEGIN_BRACE = "{"; //$NON-NLS-1$
public static final String END_BRACE = "}"; //$NON-NLS-1$
- public static final String QUOTE = "\'"; //$NON-NLS-1$
+ public static final String DOUBLEQUOTE = "\""; //$NON-NLS-1$
public static final String COLON = ":"; //$NON-NLS-1$
public static final String BEGIN_BRACKET = "["; //$NON-NLS-1$
public static final String END_BRACKET = "]"; //$NON-NLS-1$
@@ -52,8 +52,14 @@ public final class JSonHelper {
public static final String TOPIC = "Topic"; //$NON-NLS-1$
public static final String NUMERIC_PATH = "NumericPath"; //$NON-NLS-1$
- public static String getQuotes(String str){
- return ((str != null)?QUOTE + str + QUOTE:""); //$NON-NLS-1$
+ public static String getQuotes(String str) {
+ if (str == null) {
+ return ""; //$NON-NLS-1$
+ }
+ if (str.indexOf(DOUBLEQUOTE) < 0) {
+ return DOUBLEQUOTE + str + DOUBLEQUOTE;
+ }
+ return DOUBLEQUOTE + str.replaceAll(DOUBLEQUOTE, "\\\\" + DOUBLEQUOTE) + DOUBLEQUOTE; //$NON-NLS-1$
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java
index 8ec2d1bd6..fb2912396 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java
@@ -32,7 +32,8 @@ import org.junit.runners.Suite;
HelpServerInterrupt.class,
HelpServerBinding.class,
HtmlCoderTest.class,
- TocZipTest.class
+ TocZipTest.class,
+ JsonHelperTests.class
})
public class AllWebappTests {
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/JsonHelperTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/JsonHelperTests.java
new file mode 100644
index 000000000..6df0223be
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/JsonHelperTests.java
@@ -0,0 +1,17 @@
+package org.eclipse.ua.tests.help.webapp;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.help.internal.webapp.utils.JSonHelper;
+import org.junit.Test;
+
+public class JsonHelperTests {
+ @Test
+ public void testQuoted() {
+ assertEquals("\"test\"", JSonHelper.getQuotes("test"));
+ assertEquals("\"test test\"", JSonHelper.getQuotes("test test"));
+ assertEquals("\"test\\\"test\"", JSonHelper.getQuotes("test\"test"));
+ assertEquals("\"\\\"test test\\\"\"", JSonHelper.getQuotes("\"test test\""));
+ assertEquals("\"\\\\\"test test\\\\\"\"", JSonHelper.getQuotes("\\\"test test\\\""));
+ }
+}

Back to the top