fhd / clostache

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

Test fail with Clojure 1.6 (escaping backslashes) #43

Closed pesterhazy closed 7 years ago

pesterhazy commented 9 years ago

The unit test fail with current Clojure 1.6. It looks like a change between 1.4 and 1.5 broke the escaping of backslashes in the code. Maybe something related to the handling of regular expressions?

% perl -i -pe 's/1\.3\.0/1.6.0/g;' project.clj && lein test
WARNING: :warn-on-reflection is deprecated in project.clj; use :global-vars.
Reflection warning, clojure/core/incubator.clj:84:7 - reference to field getClass can't be resolved.
Reflection warning, clojure/core/incubator.clj:84:7 - reference to field isArray can't be resolved.

lein test clostache.test-parser

lein test :only clostache.test-parser/test-render-html-unescaped

FAIL in (test-render-html-unescaped) (test_parser.clj:22)
expected: (= "&\\\"<>" (render "{{{string}}}" {:string "&\\\"<>"}))
  actual: (not (= "&\\\"<>" "&\\\\\"<>"))

lein test :only clostache.test-parser/test-render-with-dollar-sign

FAIL in (test-render-with-dollar-sign) (test_parser.clj:9)
expected: (= "Hello, $Felix!" (render "Hello, {{! This is a comment.}}{{name}}!" {:name "$Felix"}))
  actual: (not (= "Hello, $Felix!" "Hello, \\$Felix!"))

lein test clostache.test-specs

Ran 42 tests containing 163 assertions.
2 failures, 0 errors.
Tests failed.
dl1ely commented 8 years ago

(render "{{{data}}}" {:data "\\"}) yields "\", not "\" as expected. Seems to be the same root cause. Tested with Clojure 1.7.0.

DanBurton commented 8 years ago

+1, I encountered the same error with rendering dollar signs.

user=> (println (mustache/render "{{money}}" {:money "$400.00"}))
\$400.00
nil
user=> (println (mustache/render "{{{money}}}" {:money "$400.00"}))
\$400.00
nil

This is with clojure-1.7.0 and clostache-1.4.0

JamesGames commented 8 years ago

With Clojure 1.8 and Clostache 1.4 I currently get:

(render "{{data}}" {:data "\\"})
=> "\\\\"
(render "{{data}}" {:data "$"})
=> "\\$"

I would expect \ and $

lsgrep commented 8 years ago

I am having the same issue.

fotoetienne commented 7 years ago

I've resolved this issue in my fork of clostache: https://github.com/fotoetienne/cljstache

fhd commented 7 years ago

Sorry, forgot about this... But better late than never. There was apparently indeed some change in Clojure 1.5 that broke this. I've made a quick fix inspired by @fotoetienne's changes for now, but I'm still curious why this broke, couldn't find anything obvious.