diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 0438e8135c87..eb784bb9ce89 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -99,6 +99,8 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLDecoder; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; @@ -726,6 +728,20 @@ public static String encode(String s) { return Util.encode(s); } + /** + * Shortcut function for calling {@link URLEncoder#encode(String,String)} (with UTF-8 encoding).
+ * Useful for encoding URL query parameters in jelly code (as in {@code "...?param=${h.urlEncode(something)}"}). + * + * @since TODO + */ + public static String urlEncode(String s) { + try { + return URLEncoder.encode(s, StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + throw new Error(e); // impossible + } + } + public static String escape(String s) { return Util.escape(s); } diff --git a/core/src/main/java/hudson/search/Search.java b/core/src/main/java/hudson/search/Search.java index 8ee98c2d5bbe..e21014a8d4f6 100644 --- a/core/src/main/java/hudson/search/Search.java +++ b/core/src/main/java/hudson/search/Search.java @@ -29,8 +29,6 @@ import hudson.util.EditDistance; import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; import java.util.AbstractList; import java.util.ArrayList; import java.util.Collections; @@ -68,10 +66,6 @@ * @see SearchableModelObject */ public class Search implements StaplerProxy { - @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 l = req.getAncestors(); diff --git a/core/src/main/resources/hudson/search/Search/search-failed.jelly b/core/src/main/resources/hudson/search/Search/search-failed.jelly index da0208682854..9248533959a8 100644 --- a/core/src/main/resources/hudson/search/Search/search-failed.jelly +++ b/core/src/main/resources/hudson/search/Search/search-failed.jelly @@ -43,13 +43,13 @@ THE SOFTWARE.
  1. - ${i.path} + ${i.path}
- result has been truncated, see 100 more + result has been truncated, see 100 more diff --git a/core/src/main/resources/lib/hudson/project/upstream-downstream.jelly b/core/src/main/resources/lib/hudson/project/upstream-downstream.jelly index e254af54478f..2040d25c5c85 100644 --- a/core/src/main/resources/lib/hudson/project/upstream-downstream.jelly +++ b/core/src/main/resources/lib/hudson/project/upstream-downstream.jelly @@ -31,7 +31,7 @@ THE SOFTWARE. - +