haskell/criterion

Presence of '\'' in the benchmark's name breaks the html report

jhrcek opened this issue · 3 comments

When I use apostrophe character in benchmark's name, all the charts in the html report are broken.

Steps to reproduce

  1. use apostrophe in benchmark's name:
module Main where

import Criterion
import Criterion.Main

main :: IO ()
main = defaultMain
    [ env (return ()) $
       \ ~() -> bgroup "Jan's benchmarks" [bench "dummy" $ nf id ()]
    ]
  1. compile the file and run it, enabling html report generation:

./mybench --output report.html

  1. Open the resulting report in the browser (I use latest google-chrom version 69)

Actual result:
none of the charts is displayed, and browser's console shows this error
Uncaught SyntaxError: Unexpected identifier
Inspecting the report more closely the error is coming from this piece of code generated in the report based on benchmark's name:

 var ylabels = [[-0,'<a href="#b0">Jan's benchmarks/dummy</a>'],];

Literal inclusion of benchmark's name into the javascript apparently leads to premature finish of the string literal, causing the sytax error.

Good catch. criterion uses the microstache library (a lighter version of stache) to substitute into criterion's HTML template, and while microstache does correctly escape some characters, it seems to miss single quotes for some reason.

While #203 does fix this issue, I think a better fix would be to fix the upstream bug at microstache. I've submitted a bug report upstream at stackbuilders/stache#35, and once that's fixed, I'll work on getting the fix into microstache itself.

Bah, it turns out that the mustache specification does not include single quotes as characters that need to be escaped, so microstache technically isn't in the wrong here. (See the discussions here and here.) In that case, it would probably be best to fix this issue on the criterion side.

I'll leave some comments on #203.

Fixed in #203.