You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by gr...@apache.org on 2020/04/24 06:21:40 UTC

[royale-compiler] branch develop updated: Fix an issue with invalid code-gen of certain XML literals with 'binding-like' value injections at construction

This is an automated email from the ASF dual-hosted git repository.

gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/develop by this push:
     new c3a5bbe  Fix an issue with invalid code-gen of certain XML literals with 'binding-like' value injections at construction
c3a5bbe is described below

commit c3a5bbec0b3c6f195a8dec031d8623f5678c7101
Author: greg-dove <gr...@gmail.com>
AuthorDate: Fri Apr 24 17:28:10 2020 +1200

    Fix an issue with invalid code-gen of certain XML literals with 'binding-like' value injections at construction
---
 .../compiler/internal/codegen/js/jx/LiteralEmitter.java      | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java
index 8a83b84..1883667 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java
@@ -60,6 +60,7 @@ public class LiteralEmitter extends JSSubEmitter implements
         String s = node.getValue(true);
         if (!(node instanceof RegExpLiteralNode))
         {
+            boolean withEscapedSingleQuote = false;
             if (node.getLiteralType() == LiteralType.XML)
             {
                 boolean jsx = false;
@@ -110,10 +111,12 @@ public class LiteralEmitter extends JSSubEmitter implements
 	                            {
 	                                s = ((LiteralNode)child).getValue(true);
 	                                s = s.replace("\n", "");
-	                                if (s.contains("'"))
-	                                    sb.append("\"" + s + "\"");
-	                                else
-	                                    sb.append("'" + s + "'");
+                                    if (s.contains("'")) {
+                                        s = s.replace("'","__ESC_SNGLE_QUOT_PLACEHOLDER__");
+                                        withEscapedSingleQuote = true;
+                                    }
+
+                                    sb.append("'" + s + "'");
 	                            }
 	                            else
 	                            {
@@ -182,6 +185,7 @@ public class LiteralEmitter extends JSSubEmitter implements
             //s = "\'" + s.replaceAll("\'", "\\\\\'") + "\'";
             s = s.replaceAll("__QUOTE_PLACEHOLDER__", "\\\\\"");
             s = s.replaceAll("__ESCAPE_PLACEHOLDER__", "\\\\\\\\");
+            if (withEscapedSingleQuote) s = s.replaceAll("__ESC_SNGLE_QUOT_PLACEHOLDER__", "\\\\'");
             s = s.replaceAll("__BACKSPACE_PLACEHOLDER__", "\\\\b");
             s = s.replaceAll("__FORMFEED_PLACEHOLDER__", "\\\\f");
             s = s.replaceAll("__TAB_PLACEHOLDER__", "\\\\t");