Skip to content

Commit

Permalink
add escapes
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 28, 2018
1 parent 71f1472 commit 6eb47d2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
14 changes: 13 additions & 1 deletion dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
}
};

var escapeRE = /(?:(?:&(?:amp|gt|lt|nbsp|quot);)|"|\\|\n)/g;
var escapeMap = {
"&": '&',
">": '>',
"&lt;": '<',
"&nbsp;": ' ',
"&quot;": "\\\"",
'\\': "\\\\",
'"': "\\\"",
'\n': "\\n"
};

var parseIndex;

var pushChild = function (child, stack) {
Expand Down Expand Up @@ -102,7 +114,7 @@
pushChild({
index: parseIndex++,
type: "m-text",
content: content
content: content.replace(escapeRE, function (match) { return escapeMap[match]; })
}, stack);

return index;
Expand Down
2 changes: 1 addition & 1 deletion dist/moon.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/compiler/parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { error } from "../util/util";

const WHITESPACE_RE = /\s/;
const whitespaceRE = /\s/;
const escapeRE = /(?:(?:&(?:amp|gt|lt|nbsp|quot);)|"|\\|\n)/g;
const escapeMap = {
"&amp;": '&',
"&gt;": '>',
"&lt;": '<',
"&nbsp;": ' ',
"&quot;": "\\\"",
'\\': "\\\\",
'"': "\\\"",
'\n': "\\n"
};

let parseIndex;

const pushChild = (child, stack) => {
Expand Down Expand Up @@ -80,7 +92,7 @@ const parseText = (index, input, length, stack) => {
pushChild({
index: parseIndex++,
type: "m-text",
content: content
content: content.replace(escapeRE, (match) => escapeMap[match])
}, stack);

return index;
Expand Down

0 comments on commit 6eb47d2

Please sign in to comment.