Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jhrcek opened this issue Sep 15, 2018 · 3 comments
Closed

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

jhrcek opened this issue Sep 15, 2018 · 3 comments

Comments

@jhrcek
Copy link
Contributor

jhrcek commented Sep 15, 2018

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.

@jhrcek jhrcek changed the title Presence of '\'' in the benchmark's name breaks the final report Presence of '\'' in the benchmark's name breaks the html report Sep 15, 2018
@RyanGlScott
Copy link
Member

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.

@RyanGlScott
Copy link
Member

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.

@RyanGlScott
Copy link
Member

Fixed in #203.

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

No branches or pull requests

2 participants