提交 f46e44bb 编写于 作者: K Kohsuke Kawaguchi

[FIXED JENKINS-9009] Fixed a bug in handling ' and " in matrix build

label axis
上级 2d3608c2
......@@ -67,6 +67,9 @@ Upcoming changes</a>
In matrix security, newly added rows weren't removable
<li class=bug>
Improve the stability of the test harness
<li class=bug>
Fixed a bug in handling ' and " in matrix build label axis
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9009">issue 9009</a>)
<li class=rfe>
Performance: Specify image sizes for faster page loading
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9182">issue 9182</a>)
......
......@@ -538,6 +538,30 @@ public class Functions {
return Util.xmlEscape(s);
}
public static String htmlAttributeEscape(String text) {
StringBuilder buf = new StringBuilder(text.length()+64);
for( int i=0; i<text.length(); i++ ) {
char ch = text.charAt(i);
if(ch=='<')
buf.append("&lt;");
else
if(ch=='>')
buf.append("&gt;");
else
if(ch=='&')
buf.append("&amp;");
else
if(ch=='"')
buf.append("&quot;");
else
if(ch=='\'')
buf.append("&#39;");
else
buf.append(ch);
}
return buf.toString();
}
public static void checkPermission(Permission permission) throws IOException, ServletException {
checkPermission(Hudson.getInstance(),permission);
}
......
......@@ -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;
/**
......@@ -45,6 +49,11 @@ public class LabelAxis extends Axis {
return true;
}
@Override
public String getValueString() {
return Util.join(getValues(),"/");
}
@Extension
public static class DescriptorImpl extends AxisDescriptor {
@Override
......@@ -60,5 +69,18 @@ public class LabelAxis extends Axis {
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>')}'
}
}
}
......@@ -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();
......
......@@ -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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册