Skip to content

Commit

Permalink
[FIXED JENKINS-9009] Fixed a bug in handling ' and " in matrix build
Browse files Browse the repository at this point in the history
label axis

Originally-Committed-As: f46e44bbafb6de5c1757f63b8e3447a4743686ec
  • Loading branch information
kohsuke committed Apr 2, 2011
1 parent e76d6f6 commit eb60736
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
22 changes: 22 additions & 0 deletions core/src/main/java/hudson/matrix/LabelAxis.java
Expand Up @@ -24,9 +24,13 @@
package hudson.matrix;

import hudson.Extension;
import hudson.Functions;
import hudson.Util;
import hudson.model.Hudson;
import hudson.model.labels.LabelAtom;
import org.kohsuke.stapler.DataBoundConstructor;

import java.text.MessageFormat;
import java.util.List;

/**
Expand All @@ -45,6 +49,11 @@ public boolean isSystem() {
return true;
}

@Override
public String getValueString() {
return Util.join(getValues(),"/");
}

@Extension
public static class DescriptorImpl extends AxisDescriptor {
@Override
Expand All @@ -60,5 +69,18 @@ public boolean isInstantiable() {
Hudson h = Hudson.getInstance();
return !h.getNodes().isEmpty() || !h.clouds.isEmpty();
}

private String jsstr(String body, Object... args) {
return '\"'+Functions.jsStringEscape(String.format(body,args))+'\"';
}

public String buildLabelCheckBox(LabelAtom la, LabelAxis instance) {
return jsstr("<input type='checkbox' name='values' json='%s' ",
Functions.htmlAttributeEscape(la.getName()))
+String.format("+has(%s)+",jsstr(la.getName()))
+jsstr("/><label class='attach-previous'>%s (%s)</label>",
la.getName(),la.getDescription());
// '${h.jsStringEscape('<input type="checkbox" name="values" json="'+h.htmlAttributeEscape(l.name)+'" ')}'+has("${h.jsStringEscape(l.name)}")+'${h.jsStringEscape('/><label class="attach-previous">'+l.name+' ('+l.description+')</label>')}'
}
}
}
4 changes: 2 additions & 2 deletions core/src/main/resources/hudson/matrix/LabelAxis/config.jelly
Expand Up @@ -35,12 +35,12 @@ THE SOFTWARE.
var labels = new YAHOO.widget.TextNode("${%Labels}", tree.getRoot(), false);
var machines = new YAHOO.widget.TextNode("${%Individual nodes}", tree.getRoot(), false);

var values = (e.getAttribute("values") || "").split(/[ \n]/);
var values = (e.getAttribute("values") || "").split("/");
function has(v) {
return values.include(v) ? 'checked="checked" ' : "";
}
<j:forEach var="l" items="${app.labelAtoms}">
new YAHOO.widget.TextNode('&lt;input type="checkbox" name="values" json="${l.name}" '+has("${l.name}")+'/&gt;&lt;label class="attach-previous"&gt;${h.jsStringEscape(l.name)} (${h.jsStringEscape(l.description)})&lt;/label&gt;', ${l.isSelfLabel()?'machines':'labels'}, false);
new YAHOO.widget.TextNode(<j:out value="${descriptor.buildLabelCheckBox(l,instance)}"/>, ${l.isSelfLabel()?'machines':'labels'}, false);
</j:forEach>

tree.draw();
Expand Down
11 changes: 11 additions & 0 deletions test/src/test/groovy/hudson/matrix/MatrixProjectTest.groovy
Expand Up @@ -279,4 +279,15 @@ public class MatrixProjectTest extends HudsonTestCase {
// expected
}
}

@Bug(9009)
void testTrickyNodeName() {
def names = [ createSlave("Sean's Workstation",null,null), createSlave("John\"s Workstation",null,null) ]*.nodeName;
def p = createMatrixProject();
p.setAxes(new AxisList([new LabelAxis("label",names)]));
configRoundtrip(p);

LabelAxis a = p.axes.find("label");
assertEquals(a.values as Set,names as Set);
}
}

0 comments on commit eb60736

Please sign in to comment.