Skip to content
Browse files
[FIXED JENKINS-42390] Search results were not correctly encoding URL …
…query parameters

(cherry picked from commit 5d92057)
  • Loading branch information
stephenc authored and olivergondza committed Apr 13, 2017
1 parent 403b1ef commit a5a2bab2afcc11351c248795b25be74cb1e1251d
@@ -29,6 +29,8 @@
import hudson.util.EditDistance;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
@@ -40,6 +42,8 @@

import javax.servlet.ServletException;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
@@ -60,6 +64,11 @@
* @see SearchableModelObject
public class Search {
@Restricted(NoExternalUse.class) // used from stapler views only
public static String encodeQuery(String query) throws UnsupportedEncodingException {
return URLEncoder.encode(query, "UTF-8");

public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
List<Ancestor> l = req.getAncestors();
for( int i=l.size()-1; i>=0; i-- ) {
@@ -43,13 +43,13 @@ THE SOFTWARE.
<j:forEach var="i" items="${items}">
<li id="item_${i.path}">
<a href="?q=${i.path}">${i.path}</a>
<a href="?q=${it.encodeQuery(i.path)}">${i.path}</a>
<j:if test="${items.hasMoreResults()}">
<j:set var="max" value="${request.hasParameter('max')?request.getParameter('max'):20}"/>
<em>result has been truncated, <a href="?q=${q}&amp;max=${max+20}">see 20 more</a></em>
<em>result has been truncated, <a href="?q=${it.encodeQuery(q)}&amp;max=${max+20}">see 20 more</a></em>

0 comments on commit a5a2bab

Please sign in to comment.