fhd / clostache

{{ mustache }} for Clojure
GNU Lesser General Public License v3.0
318 stars 62 forks source link

Parser prefixes escape characters(\\) when the parameter is "$" #54

Open aravindbaskaran opened 7 years ago

aravindbaskaran commented 7 years ago

Eg 1:

(clostache.parser/render "{{Currency}} {{Price}}" {:Currency "$" :Price 230})

Output:

"\\$ 230"

Expected:

"$ 230"

Eg 2:

(clostache.parser/render "{{Currency}} {{Price}}" {:Currency "USD$" :Price 230})

Output:

"USD\\$ 230"

Expected:

"USD$ 230"

aravindbaskaran commented 7 years ago

This worked with {{&}} and {{{}}}

(clostache.parser/render "{{&Currency}} {{Price}}" {:Currency "$" :Price 230})

aravindbaskaran commented 7 years ago

Sorry, suffered a brain freeze, had some extra code that was making it work

(->
  (clostache.parser/render "{{Currency}} {{Price}}" {:Currency "USD$" :Price 230})
  (clojure.string/replace  #"\\" ""))

That's the around. Thankfully no other "\" characters are there in my template. Reopening

aravindbaskaran commented 7 years ago

Another, better workaround

(clostache.parser/render "{{#CurrencyFn}}{{/CurrencyFn}} {{Price}}" {:Currency "USD$" :Price 230 :CurrencyFn #(str "$"%)})