Skip to content
Browse files

Fix issue with carriage returns

  • Loading branch information...
1 parent 517db92 commit d81fef33f9a1dee4e3d434daf679e9e2cb36b10e @raycmorgan committed Mar 23, 2012
View
9 lib/mu/parser.js
@@ -1,6 +1,8 @@
var util = require('util'),
Buffer = require('buffer').Buffer,
+ carriage = '__MU_CARRIAGE__',
+ carriageRegExp = new RegExp(carriage, 'g'),
newline = '__MU_NEWLINE__',
newlineRegExp = new RegExp(newline, 'g');
@@ -10,7 +12,8 @@ exports.parse = function (template, options) {
}
function Parser(template, options) {
- this.template = template.replace(/\n/g, newline);
+ this.template = template.replace(/\r\n/g, carriage)
+ .replace(/\n/g, newline);
this.options = options || {};
this.sections = [];
@@ -55,7 +58,9 @@ Parser.prototype = {
index = this.buffer.length;
}
- var content = this.buffer.substring(0, index).replace(newlineRegExp, '\n');
+ var content = this.buffer.substring(0, index)
+ .replace(carriageRegExp, '\r\n')
+ .replace(newlineRegExp, '\n');
buffer = new Buffer(Buffer.byteLength(content));
if (content !== '') {
View
3 test/examples/carriage_return.html
@@ -0,0 +1,3 @@
+<b>
+{{foo}}
+</b>
View
3 test/examples/carriage_return.js
@@ -0,0 +1,3 @@
+{
+ foo: "Hello World"
+}
View
3 test/examples/carriage_return.txt
@@ -0,0 +1,3 @@
+<b>
+Hello World
+</b>
View
3 test/run_examples_test.js
@@ -7,6 +7,7 @@ mu.root = path.join(__dirname, 'examples');
[
'boolean',
+ 'carriage_return',
'comments',
'complex',
'deep_partial',
@@ -21,7 +22,7 @@ mu.root = path.join(__dirname, 'examples');
'simple',
'twice',
'two_in_a_row',
- 'unescaped',
+ 'unescaped'
].forEach(function (name) {
var js = fs.readFileSync(path.join(mu.root, name + '.js')).toString(),
text = fs.readFileSync(path.join(mu.root, name + '.txt')).toString();

0 comments on commit d81fef3

Please sign in to comment.
Something went wrong with that request. Please try again.