You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2015/12/21 20:47:22 UTC
git commit: [flex-falcon] [refs/heads/develop] - FLEX-34989 handle
quotes and unicode line breaks in string output
Repository: flex-falcon
Updated Branches:
refs/heads/develop 3d99cff04 -> 3b19a0737
FLEX-34989 handle quotes and unicode line breaks in string output
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/3b19a073
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/3b19a073
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/3b19a073
Branch: refs/heads/develop
Commit: 3b19a07370e2c8daf2610e217bcbe16c53c9b19e
Parents: 3d99cff
Author: Alex Harui <ah...@apache.org>
Authored: Mon Dec 21 11:47:10 2015 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Mon Dec 21 11:47:10 2015 -0800
----------------------------------------------------------------------
.../js/flexjs/TestFlexJSExpressions.java | 42 ++++++++++++++++++++
.../internal/codegen/js/jx/LiteralEmitter.java | 19 +++++++++
2 files changed, 61 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3b19a073/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
index c7d02ea..bae2d0c 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
@@ -24,6 +24,7 @@ import org.apache.flex.compiler.driver.IBackend;
import org.apache.flex.compiler.internal.codegen.js.goog.TestGoogExpressions;
import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend;
import org.apache.flex.compiler.internal.tree.as.ClassNode;
+import org.apache.flex.compiler.internal.tree.as.LiteralNode;
import org.apache.flex.compiler.internal.tree.as.NodeBase;
import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
import org.apache.flex.compiler.tree.as.IClassNode;
@@ -850,9 +851,50 @@ public class TestFlexJSExpressions extends TestGoogExpressions
assertOut("org.apache.flex.utils.Language.is(a, b)");
}
+ @Test
+ public void testVisitStringLiteralEmbeddedDoubleQuote()
+ {
+ // a = " ' \" ";
+ LiteralNode node = (LiteralNode) getExpressionNode(
+ "a = \" ' \\\" \"", LiteralNode.class);
+ asBlockWalker.visitLiteral(node);
+ assertOut("\" ' \\\" \"");
+ }
+
+ @Test
+ public void testVisitStringLiteralSingleQuote()
+ {
+ // a = ' \' " ';
+ LiteralNode node = (LiteralNode) getExpressionNode(
+ "a = ' \\' \" '", LiteralNode.class);
+ asBlockWalker.visitLiteral(node);
+ assertOut("' \\' \" '");
+ }
+
+ @Test
+ public void testVisitStringLiteral2029()
+ {
+ // a = "\u2029";
+ LiteralNode node = (LiteralNode) getExpressionNode(
+ "a = \"\\u2029\"", LiteralNode.class);
+ asBlockWalker.visitLiteral(node);
+ assertOut("\"\\u2029\"");
+ }
+
+ @Test
+ public void testVisitStringLiteral2028()
+ {
+ // a = "\u2028";
+ LiteralNode node = (LiteralNode) getExpressionNode(
+ "a = \"\\u2028\"", LiteralNode.class);
+ asBlockWalker.visitLiteral(node);
+ assertOut("\"\\u2028\"");
+ }
+
protected IBackend createBackend()
{
return new FlexJSBackend();
}
+
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3b19a073/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
index 45c8966..6945772 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
@@ -67,6 +67,25 @@ public class LiteralEmitter extends JSSubEmitter implements
s = s.replaceAll("__TAB_PLACEHOLDER__", "\\\\t");
s = s.replaceAll("__CR_PLACEHOLDER__", "\\\\r");
s = s.replaceAll("__NEWLINE_PLACEHOLDER__", "\\\\n");
+ if (node.getLiteralType() == LiteralType.STRING)
+ {
+ char c = s.charAt(0);
+ if (c == '"')
+ {
+ s = s.substring(1, s.length() - 1);
+ s = s.replace("\"", "\\\"");
+ s = "\"" + s + "\"";
+ }
+ else if (c == '\'')
+ {
+ s = s.substring(1, s.length() - 1);
+ s = s.replace("'", "\\'");
+ s = "'" + s + "'";
+ }
+ s = s.replace("\u2028", "\\u2028");
+ s = s.replace("\u2029", "\\u2029");
+ }
+
}
if (!isWritten)