647: fixed quote/newline escaping in here documents

This commit is contained in:
satyr
2010-10-03 07:45:23 +09:00
parent 769870b493
commit ae55c70ac5
3 changed files with 44 additions and 25 deletions

View File

@@ -124,9 +124,13 @@
quote: quote,
indent: null
});
this.interpolateString(quote + doc + quote, {
heredoc: true
});
if (quote === '"') {
this.interpolateString(quote + doc + quote, {
heredoc: true
});
} else {
this.token('STRING', quote + doc + quote);
}
this.line += count(heredoc, '\n');
this.i += heredoc.length;
return true;
@@ -362,7 +366,7 @@
return accessor ? 'accessor' : false;
};
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
var _ref2, attempt, herecomment, indent, match;
var _ref2, attempt, herecomment, indent, match, quote;
_ref2 = options, indent = _ref2.indent, herecomment = _ref2.herecomment;
if (herecomment && !include(doc, '\n')) {
return doc;
@@ -381,8 +385,13 @@
if (herecomment) {
return doc;
}
doc = doc.replace(/^\n/, '').replace(RegExp("" + (options.quote), "g"), '\\$&');
if (options.quote === "'") {
quote = options.quote;
doc = doc.replace(/^\n/, '');
doc = doc.replace(/\\([\s\S])/g, function(m, c) {
return ('\n' === c || quote === c) ? c : m;
});
doc = doc.replace(RegExp("" + (quote), "g"), '\\$&');
if (quote === "'") {
doc = this.escapeLines(doc, true);
}
return doc;