Skip to content
Permalink
Browse files

Fix JENKINS-15146

  • Loading branch information
gboissinot committed Sep 23, 2012
1 parent 3e9cb61 commit 718586449693a86314242223b14813c374b8bbdc
@@ -241,8 +241,9 @@ private boolean isUnresolvedVar(String value) {
return true;
}

//Empty environment variables are acceptable
if (value.trim().length() == 0) {
return true;
return false;
}

return value.contains("$") && !value.contains("\\$");
@@ -0,0 +1,46 @@
package org.jenkinsci.plugins.envinject;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import junit.framework.Assert;
import org.jvnet.hudson.test.HudsonTestCase;

import java.util.Map;

/**
* @author Gregory Boissinot
*/
public class EnvInjectEnvVarsEmpty extends HudsonTestCase {


public void testEmptyVars1() throws Exception {

FreeStyleProject project = createFreeStyleProject();
StringBuffer propertiesContent = new StringBuffer("EMPTYVAR1=\n");
propertiesContent.append("VAR2=VAL2");
EnvInjectJobPropertyInfo jobPropertyInfo = new EnvInjectJobPropertyInfo(null, propertiesContent.toString(), null, null, null, false);
EnvInjectJobProperty envInjectJobProperty = new EnvInjectJobProperty();
envInjectJobProperty.setOn(true);
envInjectJobProperty.setInfo(jobPropertyInfo);
project.addProperty(envInjectJobProperty);

FreeStyleBuild build = project.scheduleBuild2(0).get();
Assert.assertEquals(Result.SUCCESS, build.getResult());


org.jenkinsci.lib.envinject.EnvInjectAction envInjectAction = build.getAction(org.jenkinsci.lib.envinject.EnvInjectAction.class);
Assert.assertNotNull(envInjectAction);
Map<String, String> envVars = envInjectAction.getEnvMap();
Assert.assertNotNull(envVars);


String resultValEnvVar1 = envVars.get("EMPTYVAR1");
String resultValEnvVar2 = envVars.get("VAR2");
Assert.assertNotNull(resultValEnvVar1);
Assert.assertNotNull(resultValEnvVar2);

Assert.assertTrue(resultValEnvVar1.length() == 0);
Assert.assertEquals("VAL2", resultValEnvVar2);
}
}

0 comments on commit 7185864

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