smeeb
smeeb

Reputation: 29497

Groovy (possibly Grails) escaping command-line parameters incorrectly

Please note: Even though this question involves Grails, I am almost 100% sure this is a pure Groovy issue.

I have a Grails app (Grails 2.4.5, Groovy 2.4.3) that accepts a few system properties at runtime from the command-line:

grails -Dfoo=2 -DfizzPassword="8cv$5)iEIm8K" run-app --stacktrace

In my code, I then read those sys props in as String values:

String foo = System.getProperty('foo')
String fizzPassword = System.getProperty('fizzPassword')

However, because the "fizzPassword" property has "$5" in it, Groovy is somehow escaping it:

void doSomething() {
    String foo = System.getProperty('foo')
    String password = System.getProperty('fizzPassword')

    // Prints: "Password read was: 8cv)iEIm8K."
    //
    // When it should be printing: "Password read was 8cv$5)iEIm8K."
    println "Password read was: ${password}."
}

Any ideas as to how I can pass the fizzPassword sys prop into the app, and then read it out as a String, without Groovy escaping/ignoring the "$5" (and possibly other similar things)? In short: How does one get Groovy to read sys props verbatim off the command-line?

Upvotes: 1

Views: 88

Answers (1)

cfrick
cfrick

Reputation: 37008

The problem there has nothing to do with groovy or grails. $... will be replaced from your shell:

$ echo "8cv$5)iEIm8K"
8cv)iEIm8K

You have to quote vars with sensitive chars properly. e.g. -DfizzPassword='8cv$5)iEIm8K'(note the single quotes)

Upvotes: 1

Related Questions