GWT 2.3.0

com.google.gwt.safehtml.shared
Class UriUtils

java.lang.Object
  extended by com.google.gwt.safehtml.shared.UriUtils

public final class UriUtils
extends java.lang.Object

Utility class containing static methods for validating and sanitizing URIs.


Method Summary
static java.lang.String extractScheme(java.lang.String uri)
          Extracts the scheme of a URI.
static boolean isSafeUri(java.lang.String uri)
          Determines if a String is safe to use as the value of a URI-valued HTML attribute such as src or href.
static java.lang.String sanitizeUri(java.lang.String uri)
          Sanitizes a URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

extractScheme

public static java.lang.String extractScheme(java.lang.String uri)
Extracts the scheme of a URI.

Parameters:
uri - the URI to extract the scheme from
Returns:
the URI's scheme, or null if the URI does not have one

isSafeUri

public static boolean isSafeUri(java.lang.String uri)
Determines if a String is safe to use as the value of a URI-valued HTML attribute such as src or href.

In this context, a URI is safe if it can be established that using it as the value of a URI-valued HTML attribute such as src or href cannot result in script execution. Specifically, this method deems a URI safe if it either does not have a scheme, or its scheme is one of http, https, ftp, mailto.

Parameters:
uri - the URI to validate
Returns:
true if uri is safe in the above sense; false otherwise

sanitizeUri

public static java.lang.String sanitizeUri(java.lang.String uri)
Sanitizes a URI.

This method returns the URI provided if it is safe to use as the the value of a URI-valued HTML attribute according to isSafeUri(java.lang.String), or the URI "#" otherwise.

Parameters:
uri - the URI to sanitize
Returns:
a sanitized String

GWT 2.3.0