Search code examples
javascriptfitnesse

Escape !- -! inside strings in javascript


I have a javascript conversion tool for moving XML into Fitnesse tables running on a Fitnesse Static Page, in which I use !- and -! around CamelCase and xmlns to avoid Fitnesse from processing them. Ironically, the use of these is causing Fitnesse to interpret them when I run the conversion tool (I take a big string var and do a $("#div").html(output); which is causing some funkiness with Fitnesse.

I have the javascript running inside !- and -!, and when building these fitnesse tables, I set it up like this:

|key|!-CamelCaseValue-!|

The javascript looks like this:

output += "!-" + currentValue + "-!";

Fitnesse looks like it is ending the script here. How can I escape these?


Solution

  • Option 1

    var startToken = "!" + "-";
    var endToken  = "-" + "!";
    
    output += startToken + currentValue + endToken;
    

    Option 2

    output += "!\-" + currentValue + "-\!";