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

joshtynjala 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 e398fd6a8 MXMLRoyaleEmitter: allow unicode escape sequences in MXML 
strings
e398fd6a8 is described below

commit e398fd6a800cc34436551a3161580f9e98d169f0
Author: Josh Tynjala <[email protected]>
AuthorDate: Thu Mar 13 10:14:49 2025 -0700

    MXMLRoyaleEmitter: allow unicode escape sequences in MXML strings
    
    For example, \u00B0 should display the degree symbol.
    
    Other escape sequences are rewritten, though. So \n or \t are still not 
allowed. I also added \b and \f, which were missing.
    
    This improves compatibility with the Flex SDK compiler.
---
 .../compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java  | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java
 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java
index 909c3f3b9..c593c1031 100644
--- 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java
+++ 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java
@@ -32,6 +32,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.regex.Matcher;
 import java.util.Set;
 import java.util.Stack;
 
@@ -3330,18 +3331,21 @@ public class MXMLRoyaleEmitter extends MXMLEmitter 
implements
         String s = node.getValue().toString();
         if (ps.valueNeedsQuotes)
         {
-            // all backslashes in the value need to be be escaped
+            // most backslashes in the value need to be be escaped
             // for example: we don't want "\" + "n" to be treated as a new 
line,
             // so it should become "\" + "\" + "n" instead. to insert a new 
line
             // in MXML, use &#xA; instead.
-            s = s.replace("\\", "\\\\");
+            // Unicode escape sequences are allowed, though.
+            s = s.replaceAll("\\\\(?!u)", Matcher.quoteReplacement("\\\\"));
 
             // the string will be wrapped with single quotes, so escape all
             // existing single quotes found within the string
             s = s.replace(ASEmitterTokens.SINGLE_QUOTE.getToken(),
                     "\\" + ASEmitterTokens.SINGLE_QUOTE.getToken());
         }
+        s = s.replace("\b", "\\b");
         s = s.replace("\t", "\\t");
+        s = s.replace("\f", "\\f");
         s = s.replace("\r", "\\r");
         s = s.replace("\n", "\\n");
         ps.value += s;

Reply via email to