Escape strings with string_escape rather than tojson

This commit is contained in:
Jay Kamat 2018-03-30 00:49:36 -04:00
parent 5bc794f85a
commit 7f5a79cdfd
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5
2 changed files with 7 additions and 5 deletions

View File

@ -30,7 +30,8 @@ import textwrap
import attr
from PyQt5.QtCore import pyqtSignal, QObject, QUrl
from qutebrowser.utils import log, standarddir, jinja, objreg, utils
from qutebrowser.utils import (log, standarddir, jinja, objreg, utils,
javascript)
from qutebrowser.commands import cmdutils
from qutebrowser.browser import downloads
@ -106,9 +107,10 @@ class GreasemonkeyScript:
"""
template = jinja.js_environment.get_template('greasemonkey_wrapper.js')
return template.render(
scriptName="/".join([self.namespace or '', self.name]),
scriptName=javascript.string_escape(
"/".join([self.namespace or '', self.name])),
scriptInfo=self._meta_json(),
scriptMeta=self.script_meta,
scriptMeta=javascript.string_escape(self.script_meta),
scriptSource=self._code)
def _meta_json(self):

View File

@ -1,5 +1,5 @@
(function() {
const _qute_script_id = "__gm_" + {{ scriptName | tojson }};
const _qute_script_id = "__gm_" + "{{ scriptName }}";
function GM_log(text) {
console.log(text);
@ -7,7 +7,7 @@
const GM_info = {
'script': {{ scriptInfo }},
'scriptMetaStr': {{ scriptMeta | tojson }},
'scriptMetaStr': "{{ scriptMeta }}",
'scriptWillUpdate': false,
'version': "0.0.1",
// so scripts don't expect exportFunction