Uri Extends
This class contains setters and getters for the parts of the URI. The getXyz/setXyz methods return the decoded part -- sogoog.Uri.parse('/foo%20bar').getPath() will return the decoded path, /foo bar. The constructor accepts an optional unparsed, raw URI string. The parser is relaxed, so special characters that aren't escaped but don't cause ambiguities will not cause parse failures. All setters return this and so may be chained, a la goog.Uri.parse('/foo').setFragment('part').toString().

Inheritance

Constructor

goog.Uri(opt_uriopt_ignoreCase)

Parameters

opt_uri : *=
Optional string URI to parse (use goog.Uri.create() to create a URI from parts), or if a goog.Uri is passed, a clone is created.
opt_ignoreCase : boolean=
If true, #getParameterValue will ignore the case of the parameter name.

Instance Methods

Public Protected Private
Defined in goog.Uri
clone() !goog.Uri
Clones the URI instance.
Returns: !goog.Uri  New instance of the URI object.
code »
enforceReadOnly()
Checks if this Uri has been marked as read only, and if so, throws an error. This should be called whenever any modifying function is called.
code »
getDecodedQuery() string
No description.
Returns: string  The decoded URI query, not including the ?.
code »
getDomain() string
No description.
Returns: string  The decoded domain.
code »
getEncodedQuery() string
No description.
Returns: string  The encoded URI query, not including the ?.
code »
getFragment() string
No description.
Returns: string  The URI fragment, not including the #.
code »
getIgnoreCase() boolean
No description.
Returns: boolean  Whether to ignore case.
code »
getParameterValue(paramName) string | undefined
Returns the first value for a given cgi parameter or undefined if the given parameter name does not appear in the query string.
Arguments:
paramName : string
Unescaped parameter name.
Returns: string | undefined  The first value for a given cgi parameter or undefined if the given parameter name does not appear in the query string.
code »
getParameterValues(name) !Array
Returns the values for a given cgi parameter as a list of decoded query parameter values.
Arguments:
name : string
The parameter to get values for.
Returns: !Array  The values for a given cgi parameter as a list of decoded query parameter values.
code »
getPath() string
No description.
Returns: string  The decoded path.
code »
getPort() ?number
No description.
Returns: ?number  The port number.
code »
getQuery() string
No description.
Returns: string  The encoded URI query, not including the ?. Warning: This method, unlike other getter methods, returns encoded value, instead of decoded one.
code »
getQueryData() !goog.Uri.QueryData
Returns the query data.
Returns: !goog.Uri.QueryData  QueryData object.
code »
getScheme() string
No description.
Returns: string  The encoded scheme/protocol for the URI.
code »
getUserInfo() string
No description.
Returns: string  The decoded user info.
code »
hasDomain() boolean
No description.
Returns: boolean  Whether the domain has been set.
code »
hasFragment() boolean
No description.
Returns: boolean  Whether the URI has a fragment set.
code »
hasPath() boolean
No description.
Returns: boolean  Whether the path has been set.
code »
hasPort() boolean
No description.
Returns: boolean  Whether the port has been set.
code »
hasQuery() boolean
No description.
Returns: boolean  Whether the query string has been set.
code »
hasSameDomainAs(uri2) boolean
Returns true if this has the same domain as that of uri2.
Arguments:
uri2 : goog.Uri
The URI object to compare to.
Returns: boolean  true if same domain; false otherwise.
code »
hasScheme() boolean
No description.
Returns: boolean  Whether the scheme has been set.
code »
hasUserInfo() boolean
No description.
Returns: boolean  Whether the user info has been set.
code »
isReadOnly() boolean
No description.
Returns: boolean  Whether the URI is read only.
code »
makeUnique() !goog.Uri
Adds a random parameter to the Uri.
Returns: !goog.Uri  Reference to this Uri object.
code »
removeParameter(key) !goog.Uri
Removes the named query parameter.
Arguments:
key : string
The parameter to remove.
Returns: !goog.Uri  Reference to this URI object.
code »
resolve(relativeUri) !goog.Uri
Resolves the given relative URI (a goog.Uri object), using the URI represented by this instance as the base URI. There are several kinds of relative URIs:
1. foo - replaces the last part of the path, the whole query and fragment
2. /foo - replaces the the path, the query and fragment
3. //foo - replaces everything from the domain on. foo is a domain name
4. ?foo - replace the query and fragment
5. #foo - replace the fragment only Additionally, if relative URI has a non-empty path, all ".." and "." segments will be resolved, as described in RFC 3986.
Arguments:
relativeUri : goog.Uri
The relative URI to resolve.
Returns: !goog.Uri  The resolved URI.
code »
setDomain(newDomainopt_decode) !goog.Uri
Sets the domain.
Arguments:
newDomain : string
New domain value.
opt_decode : boolean=
Optional param for whether to decode new value.
Returns: !goog.Uri  Reference to this URI object.
code »
setFragment(newFragmentopt_decode) !goog.Uri
Sets the URI fragment.
Arguments:
newFragment : string
New fragment value.
opt_decode : boolean=
Optional param for whether to decode new value.
Returns: !goog.Uri  Reference to this URI object.
code »
setIgnoreCase(ignoreCase) !goog.Uri
Sets whether to ignore case. NOTE: If there are already key/value pairs in the QueryData, and ignoreCase_ is set to false, the keys will all be lower-cased.
Arguments:
ignoreCase : boolean
whether this goog.Uri should ignore case.
Returns: !goog.Uri  Reference to this Uri object.
code »
setParameterValue(keyvalue) !goog.Uri
Sets the value of the named query parameters, clearing previous values for that key.
Arguments:
key : string
The parameter to set.
value : *
The new value.
Returns: !goog.Uri  Reference to this URI object.
code »
setParameterValues(keyvalues) !goog.Uri
Sets the values of the named query parameters, clearing previous values for that key. Not new values will currently be moved to the end of the query string. So, goog.Uri.parse('foo?a=b&c=d&e=f').setParameterValues('c', ['new']) yields foo?a=b&e=f&c=new.
Arguments:
key : string
The parameter to set.
values : *
The new values. If values is a single string then it will be treated as the sole value.
Returns: !goog.Uri  Reference to this URI object.
code »
setPath(newPathopt_decode) !goog.Uri
Sets the path.
Arguments:
newPath : string
New path value.
opt_decode : boolean=
Optional param for whether to decode new value.
Returns: !goog.Uri  Reference to this URI object.
code »
setPort(newPort) !goog.Uri
Sets the port number.
Arguments:
newPort : *
Port number. Will be explicitly casted to a number.
Returns: !goog.Uri  Reference to this URI object.
code »
setQuery(newQueryopt_decode) !goog.Uri
Sets the URI query.
Arguments:
newQuery : string
New query value.
opt_decode : boolean=
Optional param for whether to decode new value.
Returns: !goog.Uri  Reference to this URI object.
code »
setQueryData(queryDataopt_decode) !goog.Uri
Sets the query data.
Arguments:
queryData : goog.Uri.QueryData | string | undefined
QueryData object.
opt_decode : boolean=
Optional param for whether to decode new value. Applies only if queryData is a string.
Returns: !goog.Uri  Reference to this URI object.
code »
setReadOnly(isReadOnly) !goog.Uri
Sets whether Uri is read only. If this goog.Uri is read-only, enforceReadOnly_ will be called at the start of any function that may modify this Uri.
Arguments:
isReadOnly : boolean
whether this goog.Uri should be read only.
Returns: !goog.Uri  Reference to this Uri object.
code »
setScheme(newSchemeopt_decode) !goog.Uri
Sets the scheme/protocol.
Arguments:
newScheme : string
New scheme value.
opt_decode : boolean=
Optional param for whether to decode new value.
Returns: !goog.Uri  Reference to this URI object.
code »
setUserInfo(newUserInfoopt_decode) !goog.Uri
Sets the userInfo.
Arguments:
newUserInfo : string
New userInfo value.
opt_decode : boolean=
Optional param for whether to decode new value.
Returns: !goog.Uri  Reference to this URI object.
code »
toString() string
No description.
Returns: string  The string form of the url.
code »

Instance Properties

Defined in goog.Uri
domain_ :
Domain part, e.g. "www.google.com".
Code »
fragment_ :
The fragment without the #.
Code »
ignoreCase_ :
Whether or not to ignore case when comparing query params.
Code »
isReadOnly_ :
Whether or not this Uri should be treated as Read Only.
Code »
path_ :
Path, e.g. "/tests/img.png".
Code »
port_ :
Port, e.g. 8080.
Code »
queryData_ : goog.Uri.QueryData
Object representing query data.
Code »
scheme_ :
Scheme such as "http".
Code »
userInfo_ :
User credentials in the form "username:password".
Code »

Static Methods

goog.Uri.create(opt_schemeopt_userInfoopt_domainopt_portopt_pathopt_queryopt_fragmentopt_ignoreCase) !goog.Uri
Creates a new goog.Uri object from unencoded parts.
Arguments:
opt_scheme : ?string=
Scheme/protocol or full URI to parse.
opt_userInfo : ?string=
username:password.
opt_domain : ?string=
opt_port : ?number=
9830.
opt_path : ?string=
/some/path/to/a/file.html.
opt_query : string | goog.Uri.QueryData=
a=1&b=2.
opt_fragment : ?string=
The fragment without the #.
opt_ignoreCase : boolean=
Whether to ignore parameter name case in #getParameterValue.
Returns: !goog.Uri  The new URI object.
code »
goog.Uri.decodeOrEmpty_(val) string
Decodes a value or returns the empty string if it isn't defined or empty.
Arguments:
val : string | undefined
Value to decode.
Returns: string  Decoded value.
code »
goog.Uri.encodeChar_(ch) string
Converts a character in [\01-\177] to its unicode character equivalent.
Arguments:
ch : string
One character string.
Returns: string  Encoded string.
code »
goog.Uri.encodeSpecialChars_(unescapedPartextra) ?string
If unescapedPart is non null, then escapes any characters in it that aren't valid characters in a url and also escapes any special characters that appear in extra.
Arguments:
unescapedPart : *
The string to encode.
extra : RegExp
A character set of characters in [\01-\177].
Returns: ?string  null iff unescapedPart == null.
code »
goog.Uri.haveSameDomain(uri1Stringuri2String) boolean
Checks whether two URIs have the same domain.
Arguments:
uri1String : string
First URI string.
uri2String : string
Second URI string.
Returns: boolean  true if the two URIs have the same domain; false otherwise.
code »
goog.Uri.parse(uriopt_ignoreCase) !goog.Uri
Creates a uri from the string form. Basically an alias of new goog.Uri(). If a Uri object is passed to parse then it will return a clone of the object.
Arguments:
uri : *
Raw URI string or instance of Uri object.
opt_ignoreCase : boolean=
Whether to ignore the case of parameter names in #getParameterValue.
Returns: !goog.Uri  The new URI object.
code »
goog.Uri.removeDotSegments(path) string
Removes dot segments in given path component, as described in RFC 3986, section 5.2.4.
Arguments:
path : string
A non-empty path component.
Returns: string  Path component with removed dot segments.
code »
goog.Uri.resolve(baserel) !goog.Uri
Resolves a relative Uri against a base Uri, accepting both strings and Uri objects.
Arguments:
base : *
Base Uri.
rel : *
Relative Uri.
Returns: !goog.Uri  Resolved uri.
code »

Static Properties

goog.Uri.RANDOM_PARAM :
Parameter name added to stop caching.
Code »
goog.Uri.preserveParameterTypesCompatibilityFlag :
If true, we preserve the type of query parameters set programmatically. This means that if you set a parameter to a boolean, and then call getParameterValue, you will get a boolean back. If false, we will coerce parameters to strings, just as they would appear in real URIs. TODO(nicksantos): Remove this once people have time to fix all tests.
Code »
goog.Uri.reDisallowedInAbsolutePath_ :
Regular expression for characters that are disallowed in an absolute path.
Code »
goog.Uri.reDisallowedInFragment_ :
Regular expression for characters that are disallowed in the fragment.
Code »
goog.Uri.reDisallowedInQuery_ :
Regular expression for characters that are disallowed in the query.
Code »
goog.Uri.reDisallowedInRelativePath_ :
Regular expression for characters that are disallowed in a relative path.
Code »
goog.Uri.reDisallowedInSchemeOrUserInfo_ :
Regular expression for characters that are disallowed in the scheme or userInfo part of the URI.
Code »

Package Uri

Package Reference