add template.JSEscapeString to ensure ExecJs normal execution

This commit is contained in:
unknown
2021-10-05 09:45:36 +08:00
parent 9e347bf71f
commit 9949420639
2 changed files with 4 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ package darwin
import (
"context"
"encoding/json"
"html/template"
"log"
"runtime"
@@ -310,7 +311,7 @@ func (f *Frontend) Notify(name string, data ...interface{}) {
f.logger.Error(err.Error())
return
}
f.ExecJS(`window.wails.EventsNotify('` + string(payload) + `');`)
f.ExecJS(`window.wails.EventsNotify('` + template.JSEscapeString(string(payload)) + `');`)
}
//func (f *Frontend) processRequest(req *edge.ICoreWebView2WebResourceRequest, args *edge.ICoreWebView2WebResourceRequestedEventArgs) {

View File

@@ -11,6 +11,7 @@ import (
"runtime"
"strconv"
"strings"
"text/template"
"github.com/leaanthony/slicer"
@@ -337,7 +338,7 @@ func (f *Frontend) Notify(name string, data ...interface{}) {
f.logger.Error(err.Error())
return
}
f.ExecJS(`window.wails.EventsNotify('` + string(payload) + `');`)
f.ExecJS(`window.wails.EventsNotify('` + template.JSEscapeString(string(payload)) + `');`)
}
func (f *Frontend) processRequest(req *edge.ICoreWebView2WebResourceRequest, args *edge.ICoreWebView2WebResourceRequestedEventArgs) {