Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
The property interpolation in pom has several limitation:
1. Using properties in groovy script (GMaven), or java code in evaluateBeanshell, when the property contains backslash(), it isn't escaped. There is no chance to escape the backslash in java code because it is already evaluated by the java compiler and the backslash is gone before it is seen by user program. There is no way to escape at all.
2. Using properties in URL, especially in request parameters, the property isn't encoded, and the result URL contains ambiguous '&', '?' characters which are treated as parameter separator.
3. Using properties in XML or HTML, the '<', '>' and '&' should be encoded.
4. Using properties in exec plugin argument, when the execution is bash or cmd.exe, the '$' or '%' should be escaped. So these literal characters won't be treated as environ variable reference. And also '>', '<', '|' pipe redirections.
And lot of more limitation you can imagine.
The solution is introduce a format modifier in the property reference:
$
{property:~format(format-parameter, ...)}where the format specify the output format of property, for example:
property file='somedir\test\A&B company/guy@localhost/price $100, rate 0.1% report.xml'
$
{file:~string} format as java string, escape \ and "'somedir\\test
A&B company/guy@localhost/price $100, rate 0.1% report.xml'
${file:~shell} format as unix shell string, escape \, $, (, ), <, >, |
'somedir\\test
A&B company/guy@localhost/price \$100, rate 0.1% report.xml'
${file:~url(UTF-8)} format as URL address with characters encoded in UTF-8, using URLEncoder.
'somedir\test\A&B company/guy@localhost/price $100, rate 0.1% report.xml'
${file:~xml} format as XML text, escape &, <, >
'somedir\test\A&B company/guy@localhost/price $100, rate 0.1% report.xml'
${file:~perl} format as perl double-quoted string, escape \, $, @
'somedir\\test
A&B company/guy@localhost/price \$100, rate 0.1% report.xml'
${file:~cmd} format as win32 cmd script(.bat), escape ^, %, !, (, ), <, >, |
'somedir\test\A^&B company/guy@localhost/price $100, rate 0.1^% report.xml'
${file:~text} a canonical form of ${file}
And a recursive invocation of format:
$
{file:~xml:~string} embed the formatted XML text in java string
'somedir\\test
A&B company/guy@localhost/price $100, rate 0.1% report.xml'
$
{file:~shell:~perl} embed the shell escaped string in perl string
'somedir\\\\test\\\\A&B company/guy@localhost/price \\\$100, rate 0.1% report.xml'
Translate usage:
$
{file:~hex(utf-16le)}encode in UTF-16LE charset and then convert to hex string
$
{file:~base64(GBK)}encode in GBK charset and then convert to base64 string
$
{file:~md5(utf-8)}get MD5 digest of UTF-8 encoded string in hex form
$
{file:~sha1}get SHA-1 digest of system default charset encoded string in hex form
Patch on trunk.