shithub: mycel

Download patch

ref: f1749d6a57566ec4b0984df50c940762ac1d8db9
parent: 900ecca8a7356d55faef6990f9191a6b2a9c9fd9
author: Philip Silva <philip.silva@protonmail.com>
date: Fri Mar 5 12:11:21 EST 2021

js: properly deal with compatiblity comment

--- a/domino/domino.go
+++ b/domino/domino.go
@@ -149,7 +149,7 @@
 }
 
 func (d *Domino) Exec(script string, initial bool) (res string, err error) {
-	script = strings.Replace(script, "<!--", "", -1)
+	script = strings.Replace(script, "<!--", "//", -1)
 	SCRIPT := domIntf + script
 	if !initial {
 		SCRIPT = script
--- a/domino/domino_test.go
+++ b/domino/domino_test.go
@@ -720,3 +720,23 @@
 	}
 	d.Stop()
 }
+
+func TestNoJsCompatComment(t *testing.T) {
+	d := NewDomino(simpleHTML, nil, nil)
+	d.Start()
+	script := `
+<!--
+	const a = 1;
+	a + 7;
+// -->
+	`
+	res, err := d.Exec(script, true)
+	if err != nil {
+		t.Fatalf("%v", err)
+	}
+	t.Logf("res=%v", res)
+	if res != "8" {
+		t.Fatal()
+	}
+	d.Stop()
+}