You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2025/04/17 22:56:40 UTC

(royale-compiler) 02/02: JSRoyaleASDocEmitter: improve escaping of asdoc tag descriptions

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

commit 70c41c39fe49a87f97f48779ee82968147b0037f
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Apr 17 15:29:26 2025 -0700

    JSRoyaleASDocEmitter: improve escaping of asdoc tag descriptions
    
    In particular, anything that should be escaped in a JSON string, but also a bit of normalization too
---
 .../codegen/js/royale/JSRoyaleASDocEmitter.java    | 27 +++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java
index 580121d84..f5c368904 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java
@@ -626,10 +626,31 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
     					firstOne = false;
     					write("\"");
     					d = value.getDescription().trim();
-    					d = d.replace("\t", " ");
-    					d = d.replace("\\\"", "&quot;");
+
+						// escape all backslashes first because we might add
+						// more backslashes when we escape other stuff
+						// and we don't want to double escape those backslashes
     					d = d.replace("\\", "\\\\");
-    					write(d);
+
+						// we're wrapping the string with double quotes, so
+						// escape any double quotes that will appear inside them
+    					d = d.replace("\"", "\\\"");
+    					
+						// collapse tabs to spaces
+						d = d.replace("\t", " ");
+
+						// convert all other types of new lines to \n for consistency
+    					d = d.replace("\r\n", "\n");
+    					d = d.replace("\r", "\n");
+
+						// then escape all new lines
+    					d = d.replace("\n", "\\n");
+
+						// these characters don't make sense, so remove them
+						d = d.replace("\b", "");
+    					d = d.replace("\f", "");
+
+						write(d);
     					write("\"");
     				}
     			}