tj / ejs

Embedded JavaScript templates for node
4.47k stars 512 forks source link

conflicts with colon #80

Open harrisonyao opened 11 years ago

harrisonyao commented 11 years ago

Hi there,

I was encountered the issue about the conflicts with ejs filter expression, eg: one expression with the content: <%=: varObj | dateformat 'yyyy-MM-dd hh:mm:ss' %> and the first colon with the tag "<%=:" is the filter tag in ejs, but the customized filter which named as "dateformat" will accept the format string some like the pattern "yyyy-MM-dd hh:mm:ss", and the format pattern string have the colons also as the parameter which will be passed into the filter function, so ejs will give the error stack info as: "500 SyntaxError: Unexpected token : "

So, it is just a advice that to enable the customized the filter express tag with ejs template file in ejs engine configurations.

Thanks, -Harrison

harrisonyao commented 11 years ago

Sorry for the wrong expression, it should be "<%=: varObj | dateformat:'yyyy-MM-dd hh:mm:ss' %>" , but the issue is still there ^-^

ralyodio commented 11 years ago

If you're formatting dates, I would export momentjs into the view, I would just do this: app.locals.moment = require('moment');

then in your view, you can do <%= moment(foo.created_at).fromNow() %>

harrisonyao commented 11 years ago

that's fine and it works, thanks a lot :-) , but it is still a issue ( or risk ) for filters in ejs template when used with the parameter will include colon. Hopes any changes on it ....

ralyodio commented 11 years ago

Did you try escaping them? :

tj commented 11 years ago

ah yeah that's definitely a bug