Java URL Sanitize sanitizeForNextUrl(String url)

Here you can find the source of sanitizeForNextUrl(String url)

Description

Sanitizes the given URL for the parameter Const.ParamsNames#NEXT_URL .

License

Open Source License

Return

the sanitized url or null (if the parameter was null).

Declaration

public static String sanitizeForNextUrl(String url) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w w w .  j a v a  2  s.  com*/
     * Sanitizes the given URL for the parameter {@link Const.ParamsNames#NEXT_URL}.
     * The following characters will be sanitized:
     * <ul>
     * <li>&, to prevent the parameters of the next URL from being considered as
     *     part of the original URL</li>
     * <li>%2B (encoded +), to prevent Google from decoding it back to +,
     *     which is used to encode whitespace in some cases</li>
     * <li>%23 (encoded #), to prevent Google from decoding it back to #,
     *     which is used to traverse the HTML document to a certain id</li>
     * </ul>
     *
     * @return the sanitized url or null (if the parameter was null).
     */
    public static String sanitizeForNextUrl(String url) {
        if (url == null) {
            return null;
        }
        return url.replace("&", "${amp}").replace("%2B", "${plus}")
                .replace("%23", "${hash}");
    }
}

Related

  1. sanitizeCollabNetUrl(String url)
  2. sanitizeDefaultPort(String url)
  3. sanitizeUri(String uri)
  4. sanitizeUri(String uri)
  5. sanitizeURL(String url)
  6. sanitizeUrl(String url)