Skip to content
Permalink
Browse files

Drop custom parameter escaping

Escaping done by `addKeyValuePairs` is already enough.

[FIXED JENKINS-42573]
  • Loading branch information
wolfs committed Mar 10, 2017
1 parent e2a5c24 commit 7752876638cc371cb7dfaf81e35cb5644e8f10e4
@@ -10,6 +10,7 @@ In order to release this plugin have a look at [here](RELEASING.md).

## Release Notes
* 1.27 (unreleased)
* Job parameters are now correctly quoted when passed as system properties [JENKINS-42573](https://issues.jenkins-ci.org/browse/JENKINS-42573)
* Make finding wrapper location more robust on Windows
* Increase required core version to 1.642.1
* 1.26 (Feb 13 2016)
@@ -26,7 +26,6 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -274,7 +273,7 @@ private boolean performTask(boolean dryRun, AbstractBuild<?, ?> build, Launcher


Set<String> sensitiveVars = build.getSensitiveBuildVariables();
args.addKeyValuePairs(passPropertyOption(), fixParameters(build.getBuildVariables()), sensitiveVars);
args.addKeyValuePairs(passPropertyOption(), build.getBuildVariables(), sensitiveVars);
args.addTokenized(normalizedSwitches);
args.addTokenized(normalizedTasks);
if (buildFile != null && buildFile.trim().length() != 0) {
@@ -363,29 +362,6 @@ private String passPropertyOption() {
return passAsProperties ? "-P" : "-D";
}

private Map<String, String> fixParameters(Map<String, String> parmas) {
Map<String, String> result = new HashMap<String, String>();
for (Map.Entry<String, String> entry : parmas.entrySet()) {
String value = entry.getValue();
if (isValue2Escape(value)) {
result.put(entry.getKey(), "\"" + value + "\"");
} else {
result.put(entry.getKey(), value);
}
}
return result;
}

private boolean isValue2Escape(String value) {
if (value == null) {
return false;
}
if (value.trim().length() == 0) {
return false;
}
return value.contains("<") || value.contains(">");
}

@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
@@ -188,7 +188,7 @@ task hello << { println 'Hello' }"""))
'build/some/build.gradle' | [rootBuildScriptDir: 'build'] | [null]
}

def "Can use > signs in system properties"() {
def "Can use '#propertyValue' in system properties"() {
given:
gradleInstallationRule.addInstallation()
def p = j.createFreeStyleProject()
@@ -198,11 +198,20 @@ task hello << { println 'Hello' }"""))
p.buildersList.add(new Gradle(tasks: 'printParam', useWrapper: true, useWorkspaceAsHome: true))

when:
def build = j.assertBuildStatusSuccess(p.scheduleBuild2(0, new Cause.UserIdCause(), new ParametersAction(new TextParameterValue("PARAM", "a < b"))))
def build = j.assertBuildStatusSuccess(p.scheduleBuild2(0, new Cause.UserIdCause(), new ParametersAction(new TextParameterValue("PARAM", propertyValue))))

then:
// TODO: Make this return 'property=a < b'
getLog(build).contains('property="a < b"')
getLog(build).contains("property=${propertyValue}")

where:
propertyValue << [
'a < b',
'<foo> <bar/> </foo>',
'renaming XYZ >> \'xyz\'',
'renaming XYZ >>> \'xyz\'',
'renaming XYZ >> "xyz"',
'renaming \'XYZ >> \'x"y"z\'"'
]
}

def "Config roundtrip"() {

3 comments on commit 7752876

@spac3hit

This comment has been minimized.

Copy link

spac3hit replied Mar 20, 2017

Hope this will also fix this issue:

param=ghprbPullLongDescription
value= value screenshot
error:

bin/gradle: 1: eval: Syntax error: end of file unexpected
Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
@wolfs

This comment has been minimized.

Copy link
Member Author

wolfs replied Mar 20, 2017

It actually fixes the issue for multiline properties on Linux. It does not fix the issue for multi line comments on Windows, since there is a bug/missing feature in Jenkins core :(
I was going to make passing of all parameters as properties optional and introduce to extra fields for passing those: #46
Would that work for you?

@spac3hit

This comment has been minimized.

Copy link

spac3hit replied Mar 20, 2017

Yeah, fine, no problem.
Thank you.

Please sign in to comment.
You can’t perform that action at this time.