0

I have this groovy script that defines a closure that works properly.

escape = { str -> 
    str.collect{ ch ->
        def escaped = ch
        switch (ch) {
            case "\"" : escaped = "\\\"" ; break
            // other cases omitted for simplicity
        }
        escaped
    }.join()
}

assert escape("\"") == "\\\""       //Sucess

But when I add another closure that uses some GString interpolation to the script.

escape = { str -> 
    //Same as above
}

dummy = {
    aStr = "abc"
    "123${aStr}456"
}

//Compilation fails

I get the error

javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script650.groovy: 7: expecting anything but ''\n''; got it anyway @ line 7, column 39.
        case "\"" : escaped = "\\"" ; break
                                 ^

1 error

Even if the added closure was commented.

escape = { str -> 
    //Same as above
}

/*dummy = {
    aStr = "abc"
    "123${aStr}456"
}*/

//Compilation fails

Still fails! What gives?

  • above code pasted into a groovy file runs fine with 2.4. since above error would indicate, that one `\` is missing, could it be an error when the script is read/passed down? and does it work when using '"' and '\\"' instead (more readable anyway)? – cfrick Mar 02 '15 at 09:53
  • @cfrick, Thanks for the tip. I suspected this to be a JMeter specific bug in passing of script text, rather than of groovy itself. Will definitely try '"' :).In regards to readability, I prefer all my string literals to be double quoted. Any other quoting syntax should reflect differing of type from being a String. – Gomain Hoyes Mar 06 '15 at 04:54

0 Answers0