mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-19 03:44:23 -05:00
647: fixed quote/newline escaping in here documents
This commit is contained in:
21
lib/lexer.js
21
lib/lexer.js
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user