From 281e45d6baa5c58c9e82050d97b7a97eb50269c0 Mon Sep 17 00:00:00 2001 From: Alan Johnson Date: Mon, 13 Sep 2010 20:30:15 -0400 Subject: [PATCH] Got carriage returns working. --- lib/handlebars.js | 3 +++ test/handlebars.js | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/lib/handlebars.js b/lib/handlebars.js index 3d651154..cbb8a28d 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -231,6 +231,9 @@ Handlebars.Compiler.prototype = { if(chr === "\n") { this.newlines = this.newlines + "\n"; chr = "\\n"; + } else if (chr === "\r") { + this.newlines = this.newlines + "\r"; + chr = "\\r"; } this.text = this.text + chr; } diff --git a/test/handlebars.js b/test/handlebars.js index 649830f0..7b5744e0 100644 --- a/test/handlebars.js +++ b/test/handlebars.js @@ -26,6 +26,11 @@ test("boolean", function() { "booleans do not show the contents when false"); }); +test("newlines", function() { + shouldCompileTo("Alan's\nTest", {}, "Alan's\nTest"); + shouldCompileTo("Alan's\rTest", {}, "Alan's\rTest"); +}); + test("escaping text", function() { shouldCompileTo("Awesome's", {}, "Awesome's", "text is escaped so that it doesn't get caught on single quotes"); shouldCompileTo("Awesome\\", {}, "Awesome\\", "text is escaped so that the closing quote can't be ignored");