Fixed escaper initialization issue #50

wants to merge 6 commits into


None yet
2 participants

ilich commented Nov 19, 2011

Hi Tim,

Thank you for the great project. It is really useful and saved me a lot of time.

Yesterday I found an issue with Haml.render function. For example, if you have a document:
$title&= title

Then you tries to call Haml.render(doc, { locals: { title: "The test" } }); The call fails with the error of undefined function.

The issue is &= title converted to undefined(title) call what is wrong. I modified the code to initialize escaper function in the render method as well. It has been initialized only in Haml(haml, config) function before.

The second change was to fix how you process end of line characters on Windows. Unit had tests because they expected to have \r\n in a rendered content but there were just \n or \n\n. I fixed the issue: if the platform is Windows then use \r\n otherwise just \n.

I also added a possibility to run only selected tests. For example, node tests.js comments.haml.

I changed deprecated module 'sys' with 'utils' in the tests.js

Please let me know if you have questions or concerns. Otherwise please merge them to the main branch.

Best regards,

Fixed issue with uninitialized escapers in Haml.render function. Fixe…
…d issue with new line on Windows (use \r\n instead of \n when running on Windows). Fixed unit tests. Added posibility to run only some tests from the test kit. Use util module instead of deprecated sys module.
@@ -3,6 +3,9 @@ var Haml;
(function () {
var matchers, self_close_tags, embedder, forceXML, escaperName, escapeHtmlByDefault;
+ var NEW_LINE_STR = process.platform.match(/^win/i) ? "\\r\\n" : "\\n";

lashd Dec 8, 2011

I am using haml-sprockets in my ruby app and serve haml.js to render my templates on the client. This line causes the following error: 'process is not defined' Is this a Node specific change?


ilich Dec 9, 2011

Yes, it's Node specific which represents the running process.

I would change

var NEW_LINE_STR = process.platform.match(/^win/i) ? "\r\n" : "\n";


var NEW_LINE_STR = "'n";

to be able to run the script in a web-browser.


lashd Dec 9, 2011

So if this pull request is accepted, users would need to manually edit haml.js to be able to continue to use it on the client side?


ilich Dec 9, 2011

that's the good point. I will try to fix this issue to fix the code for web-browsers as well,

thank you for testing. I've been using the library only from node.js.


lashd Dec 9, 2011

no problem :)

I know this isn't strictly the right place to put this...
But I have found that nesting inline javascript in any control structure doesn't work... I am digging in to this but it's a bit of a headache... Have you noticed this?

:each number in [1,2,3,4]

  • var temp = 1 + number

ilich commented Dec 9, 2011

I've created a fix for a web-browser. Please, retest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment