Skip to content

Commit e776156

Browse files
author
David Håsäther
committed
Fix for DFL-3303: escape_input() doesn't escape enough characters.
1 parent 46cb0dd commit e776156

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

src/ecma-debugger/dominspection/attrandtextditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var DOMAttrAndTextEditor = function(nav_filters)
77
{
88
var crlf_encode = function(str)
99
{
10-
return helpers.escape_input(str).replace(/\r\n/g, "\\n");
10+
return helpers.escape_input(str.replace(/\r\n/g, "\n"));
1111
}
1212

1313
this._onmonospacefontchange = function(msg)

src/ecma-debugger/dominspection/markupeditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ var DOMMarkupEditor = function()
207207

208208
var encode = function(str)
209209
{
210-
return helpers.escape_input(str).replace(/\r\n/g, "\\n");
210+
return helpers.escape_input(str.replace(/\r\n/g, "\n"));
211211
};
212212

213213
// class on the host side to update the given DOM range

src/ecma-debugger/helpers.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,23 @@ window.cls.Helpers = function()
139139
*/
140140
this.escape_input = (function()
141141
{
142-
var re_escape_char = /\\/g;
143-
var re_quot_mark = /"/g;
142+
var regexps = [
143+
[/\\/g, "\\\\"],
144+
[/"/g, "\\\""],
145+
[/'/g, "\\'"],
146+
[/\n/g, "\\n"],
147+
[/\r/g, "\\r"],
148+
[/\u2028/g, "\\u2028"],
149+
[/\u2029/g, "\\u2029"]
150+
];
144151

145152
return function escape_input(str)
146153
{
147-
// Need to double escape since this is a string inside a string
148-
return str.replace(re_escape_char, "\\\\")
149-
.replace(re_quot_mark, "\\\"");
154+
for (var i = 0, re; re = regexps[i]; i++)
155+
{
156+
str = str.replace(re[0], re[1]);
157+
}
158+
return str;
150159
}
151160
})();
152161

src/style/newstyle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ cls.NewStyle = function(id, name, container_class)
4545
{
4646
rt_style.css_text = this._textarea.value;
4747
var script = "try{style.textContent = \"" +
48-
window.helpers.escape_input(rt_style.css_text).replace(/\r?\n/g, "") +
48+
window.helpers.escape_input(rt_style.css_text.replace(/\r\n/g, "\n")) +
4949
"\";}catch(e){};";
5050
var tag = this._tag_manager.set_callback(this, window.element_style.update);
5151
this._es_debugger.requestEval(tag,

0 commit comments

Comments
 (0)