Skip to content
Permalink
Browse files

Merge pull request #84 from DealerDotCom/master

[FIXED JENKINS-38551] Escape invalid chars in gdsl generation
  • Loading branch information
jglick committed Nov 17, 2016
2 parents 382cf9b + d0dacb1 commit 7273d777e9ea119d0d25f42e5534dd71c1c65583
@@ -2,3 +2,5 @@ target
work
node
node_modules
.idea/
*.iml
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.workflow.cps.Snippetizer

import groovy.json.StringEscapeUtils
import hudson.FilePath
import hudson.Functions
import org.jenkinsci.plugins.structs.describable.DescribableModel
@@ -51,7 +52,8 @@ steps.each { StepDescriptor step, DescribableModel model ->

boolean requiresNode = step.requiredContext.contains(FilePath)
boolean takesClosure = step.takesImplicitBlockArgument()
String description = step.displayName
String sanitizedDisplayName = StringEscapeUtils.escapeJavaScript(step.displayName)
String description = sanitizedDisplayName
if (step.isAdvanced()) {
description = "Advanced/Deprecated " + description
}
@@ -81,7 +83,7 @@ steps.each { StepDescriptor step, DescribableModel model ->
for (def p : opts) {
paramsMap.put(p.key, p.value)
}
String contr = "method(name: '${step.functionName}', type: 'Object', useNamedArgs: true, params: ${paramsMap}, doc: '${step.displayName}')"
String contr = "method(name: '${step.functionName}', type: 'Object', useNamedArgs: true, params: ${paramsMap}, doc: '${sanitizedDisplayName}')"

if (requiresNode) {
nodeContext.add(contr)
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.workflow.cps.Snippetizer

import groovy.json.StringEscapeUtils
import hudson.FilePath
import hudson.Functions
import org.jenkinsci.plugins.structs.describable.DescribableModel
@@ -50,7 +51,8 @@ steps.each { StepDescriptor step, DescribableModel model ->

boolean requiresNode = step.requiredContext.contains(FilePath)
boolean takesClosure = step.takesImplicitBlockArgument()
String description = step.displayName
def sanitizedDisplayName = StringEscapeUtils.escapeJavaScript(step.displayName)
String description = sanitizedDisplayName
if (step.isAdvanced()) {
description = "Advanced/Deprecated " + description
}
@@ -83,9 +85,9 @@ steps.each { StepDescriptor step, DescribableModel model ->
}
String contr
if (takesClosure) {
contr = "method(name: '${step.functionName}', type: 'Object', params: [body:Closure], namedParams: [${namedParamsS.toString()}], doc: '${step.displayName}')"
contr = "method(name: '${step.functionName}', type: 'Object', params: [body:Closure], namedParams: [${namedParamsS.toString()}], doc: '${sanitizedDisplayName}')"
} else {
contr = "method(name: '${step.functionName}', type: 'Object', namedParams: [${namedParamsS.toString()}], doc: '${step.displayName}')"
contr = "method(name: '${step.functionName}', type: 'Object', namedParams: [${namedParamsS.toString()}], doc: '${sanitizedDisplayName}')"
}
if (requiresNode) {
nodeContext.add(contr)
@@ -0,0 +1,41 @@
package org.jenkinsci.plugins.workflow.testMetaStep;

import com.google.inject.Inject;
import hudson.Extension;
import hudson.model.TaskListener;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution;
import org.jenkinsci.plugins.workflow.steps.StepContextParameter;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Test class to make sure step descriptions with special characters are escaped properly.
*/
public class DisplaynameWithEscapeCharState extends AbstractStepImpl {

@DataBoundConstructor
public DisplaynameWithEscapeCharState() {}

private static final class Execution extends AbstractSynchronousNonBlockingStepExecution<Void> {
@Override protected Void run() throws Exception {
return null;
}
private static final long serialVersionUID = 1L;
}

@Extension
public static final class DescriptorImpl extends AbstractStepDescriptorImpl {
public DescriptorImpl() {
super(Execution.class);
}

@Override public String getFunctionName() {
return "displaynameWithEscapeCharState";
}

@Override public String getDisplayName() {
return "Testing 'escape characters' are added when needed.";
}
}
}

0 comments on commit 7273d77

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