Escapes a string as a URI

@param url the path to escape
@param strict whether or not to do strict escaping
@return the escaped string
546121
public static String escape(final String url, final boolean strict) {
        return (strict ? STRICT_ESCAPER : ESCAPER).escape(url);
    }
717477
public static String escapeEntities(String str, boolean strict) {
        StringBuilder buffer;
        char ch;
        String msg;
        String entity;

        buffer = null;
        for (int i = 0; i < str.length(); i++) {
            ch = str.charAt(i);
            switch (ch) {
                case '\t':
                case '\n':
                case '\r':
                    entity = null;
                    break;
                case '<' :
                    entity = "&lt;";
                    break;
                case '>' :
                    entity = "&gt;";
                    break;
                case '\'' :
                    entity = "&apos;";
                    break;
                case '\"' :
                    entity = "&quot;";
                    break;
                case '&' :
                    entity = "&amp;";
                    break;
                default :
                    if (ch < 32) {
                        msg = "illegal character code " + (int) ch;
                        if (strict) {
                            throw new IllegalArgumentException(msg);
                        }
                        entity = "[" + msg + "]";
                    } else if (ch < 256) {
                        entity = null;
                    } else {
                        entity = "&#" + (int) ch + ";";
                    }
                    break;
            }
            if (buffer == null) {
                if (entity != null) {
                    buffer = new StringBuilder(str.length() + 5);
                    buffer.append(str.substring(0, i));
                    buffer.append(entity);
                }
            } else {
                if (entity == null) {
                    buffer.append(ch);
                } else {
                    buffer.append(entity);
                }
            }
        }
        return buffer == null ? str : buffer.toString();
    }
602581
public static String getRawFragment(final URI uri, final boolean strict) {
        return esc(strict).escapeFragment(Strings.emptyToNull(uri.getRawFragment()));
    }
596597
public static String escapeForUrl(final String input) {
		if (input == null || input.length() == 0) {
			return input;
		}

		final StringBuilder buffer = new StringBuilder(input.length() * 2); // worst-case
		char[] characters = input.toCharArray();

		for (int i = 0, len = input.length(); i < len; ++i) {
			final char ch = characters[i];

			// Section 2.3 - Unreserved chars
			if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')
					|| ch == '-' || ch == '_' || ch == '.' || ch == '~') {
				buffer.append(ch);
			} else if (ch <= 127) { // Other ASCII characters must be escaped
				final String hexString = Integer.toHexString(ch);

				if (hexString.length() == 1) {
					buffer.append("%0").append(hexString);
				} else {
					buffer.append('%').append(hexString);
				}
			} else if (ch <= 0x07FF) { // Other non-ASCII chars must be UTF-8 encoded
				buffer.append('%').append(Integer.toHexString(0xc0 | (ch >> 6)));
				buffer.append('%').append(Integer.toHexString(0x80 | (ch & 0x3F)));
			} else {
				buffer.append('%').append(Integer.toHexString(0xe0 | (ch >> 12)));
				buffer.append('%').append(Integer.toHexString(0x80 | ((ch >> 6) & 0x3F)));
				buffer.append('%').append(Integer.toHexString(0x80 | (ch & 0x3F)));
			}
		}

		return buffer.toString();
	}
297203
public static URI urlToURI(URL url) {
    try {
      return url.toURI();
    }
    catch (URISyntaxException e) {
      throw LOG.cannotConvertUrlToUri(url, e);
    }
  }
806928
public static String urlEncode(final String text) throws Exception {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();

        for (int b : toUTF8Bytes(text)) {
            if (b < 0) {
                b = 256 + b;
            }

            if (UNRESERVED_CHARS.get(b)) {
                buffer.write(b);
            } else {
                buffer.write(URL_ESCAPE_CHAR);
                char hex1 = Character.toUpperCase(Character.forDigit(
                        (b >> 4) & 0xF, 16));
                char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF,
                        16));
                buffer.write(hex1);
                buffer.write(hex2);
            }
        }

        return new String(buffer.toByteArray());
    }
1307446
public static String encode(String url, String charset) throws UtilException {
		if (StrUtil.isEmpty(url)) {
			return url;
		}
		return encode(url, StrUtil.isBlank(charset) ? CharsetUtil.defaultCharset() : CharsetUtil.charset(charset));
	}
381213
@Nullable
  public String encodeURL (@Nullable final String sUrl)
  {
    if (StringHelper.hasText (m_sEncodeUrlSuffix))
      return StringHelper.getNotNull (sUrl) + m_sEncodeUrlSuffix;
    return sUrl;
  }
961549
private static String decodeURL(String url) {
    	try {
			return URLDecoder.decode(url, UTF_8);
		} catch (UnsupportedEncodingException e) {
		}
		return null;
    }
215497
@Nullable
  public String encodeRedirectURL (@Nullable final String sUrl)
  {
    if (StringHelper.hasText (m_sEncodeRedirectUrlSuffix))
      return StringHelper.getNotNull (sUrl) + m_sEncodeRedirectUrlSuffix;
    return sUrl;
  }
842093
public static String encodeRedirectURLEL(HttpServletResponse rsp, String url) {
	try {
	    return rsp.encodeRedirectURL(url);
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    return url;
	}
    }
638611
private String convertURItoURL(String uri) {
        int indexScheme = uri.indexOf("://");
        if (-1 != indexScheme) {
            int indexQuery = uri.indexOf('?');
            if (-1 == indexQuery || indexScheme < indexQuery) {
                // already a full url
                return uri;
            }
        }
        StringBuilder sb = new StringBuilder();
        String scheme = this.request.getScheme();
        sb.append(scheme).append("://");
        sb.append(this.request.getServerName());
        int port = this.request.getServerPort();
        if ("http".equalsIgnoreCase(scheme) && 80 != port) {
            sb.append(':').append(port);
        } else if ("https".equalsIgnoreCase(scheme) && 443 != port) {
            sb.append(':').append(port);
        }
        String data = this.request.getContextPath();
        if (!"".equals(data)) {
            sb.append(data);
        }
        if (0 == uri.length()) {
            sb.append('/');
        } else if (uri.charAt(0) == '/') {
            // relative to servlet container root...
            sb.append(uri);
        } else {
            // relative to current URI,
            data = this.request.getServletPath();
            if (!"".equals(data)) {
                sb.append(data);
            }
            data = this.request.getPathInfo();
            if (null != data) {
                sb.append(data);
            }
            sb.append('/');
            sb.append(uri);
            // TODO: webcontainer converted "/./" and "/../" info too
        }

        return sb.toString();
    }
1367562
public static String urlEncode(String s) {
		if (s == null) {
			return "";
		}
		String encoded = s;
		try {
			encoded = URLEncoder.encode(s, Config.DEFAULT_ENCODING);
		} catch (UnsupportedEncodingException ex) {
			logger.error(null, ex);
		}
		return encoded;
	}
1148080
public static URI urlToUri( URL url ) throws URISyntaxException {

		URI uri;
		try {
			// Possible failing step.
			uri = url.toURI();

		} catch( Exception e ) {
			// URL did not comply with RFC 2396 => illegal non-escaped characters.
			try {
				uri = new URI(
						url.getProtocol(),
						url.getUserInfo(),
						url.getHost(),
						url.getPort(),
						url.getPath(),
						url.getQuery(),
						url.getRef());

			} catch( Exception e1 ) {
				throw new URISyntaxException( String.valueOf( url ), "Broken URL." );
			}
		}

		uri = uri.normalize();
		return uri;
	}
861350
public static ExpectedCondition<Boolean> urlToBe(final String url) {
    return new ExpectedCondition<Boolean>() {
      private String currentUrl = "";

      @Override
      public Boolean apply(WebDriver driver) {
        currentUrl = driver.getCurrentUrl();
        return currentUrl != null && currentUrl.equals(url);
      }

      @Override
      public String toString() {
        return String.format("url to be \"%s\". Current url: \"%s\"", url, currentUrl);
      }
    };
  }
171804
function escapeColons(url) {
        var answer = url;
        if (_.startsWith(url, 'proxy')) {
            answer = url.replace(/:/g, '\\:');
        }
        else {
            answer = url.replace(/:([^\/])/, '\\:$1');
        }
        return answer;
    }
1219425
public String applyOnURL(String url) {
        if (StringUtils.isBlank(url)) {
            return url;
        }
        return StringUtils.substringBefore(url, "?") + toString();
    }