CenturyLinkCloud / mdw

https://centurylinkcloud.github.io/mdw/
MIT License
46 stars 10 forks source link

Automated test expected/actual YAML files cannot be parsed by Groovy if larger than 65k characters #849

Closed jbrojdeCTL closed 4 years ago

jbrojdeCTL commented 4 years ago

Groovy has a limitation in parsing scripts that have more than 65535 characters which means that automated tests that create expected/actual .yaml files cannot pass due to this error.

One approach would be to check for this and break up the content into smaller chunks to process and then put back together.

Issue happens in TestCaseRun.java class in substitute method, invoking groovy script's "parse" method (line 699):

protected String substitute(String before) { if (!before.contains("${")) return before; // escape all $ not followed by curly braces on same line before = before.replaceAll("\$(?!\{)", "\\\$"); // escape all regex -> ${~ before = before.replaceAll("\$\{~", "\\\$\{~"); // escape all escaped newlines before = before.replaceAll("\\n", "\\\\\n"); before = before.replaceAll("\\r", "\\\\\r"); // escape all escaped quotes before = before.replaceAll("\\"", "\\\"");

    CompilerConfiguration compilerCfg = new CompilerConfiguration();
    compilerCfg.setScriptBaseClass(DelegatingScript.class.getName());
    GroovyShell shell = new GroovyShell(TestCaseScript.class.getClassLoader(), getBinding(), compilerCfg);
    DelegatingScript script = (DelegatingScript) shell.parse("return \"\"\"" + before + "\"\"\"");
    script.setDelegate(TestCaseScript.this);
    // restore escaped \$ to $ for comparison
    return script.run().toString().replaceAll("\\\\$", "\\$");
  }