An array representing a set of query parameters with alternating keys
and values.
Keys are assumed to be URI encoded already and live at even indices. See
goog.uri.utils.QueryValue for details on how parameter values are encoded.
Example:
var data = [
// Simple param: ?name=BobBarker
'name', 'BobBarker',
// Conditional param -- may be omitted entirely.
'specialDietaryNeeds', hasDietaryNeeds() ? getDietaryNeeds() : null,
// Multi-valued param: &house=LosAngeles&house=NewYork&house=null
'house', ['LosAngeles', 'NewYork', null]
];
Supported query parameter values by the parameter serializing utilities.
If a value is null or undefined, the key-value pair is skipped, as an easy
way to omit parameters conditionally. Non-array parameters are converted
to a string and URI encoded. Array values are expanded into multiple
&key=value pairs, with each element stringized and URI-encoded.
Appends a single URI parameter.
Repeated calls to this can exhibit quadratic behavior in IE6 due to the
way string append works, though it should be limited given the 2kb limit.
The value, which will be stringized and encoded
(assumed not already to be encoded). If omitted, undefined, or null, the
key will be added as a valueless parameter.
Appends URI parameters to an existing URI.
The variable arguments may contain alternating keys and values. Keys are
assumed to be already URI encoded. The values should not be URI-encoded,
and will instead be encoded by this function.
A single call to this function will not exhibit quadratic behavior in IE,
whereas multiple repeated calls may, although the effect is limited by
fact that URL's generally can't exceed 2kb.
Generates a URI path using a given URI and a path with checks to
prevent consecutive "//". The baseUri passed in must not contain
query or fragment identifiers. The path to append may not contain query or
fragment identifiers.
A string buffer. The first element
must be the base URI, and may have a fragment identifier. If the array
contains more than one element, the second element must be an ampersand,
and may be overwritten, depending on the base URI. Undefined elements
are treated as empty-string.
Ensures that two URI's have the exact same domain, scheme, and port.
Unlike the version in goog.Uri, this checks protocol, and therefore is
suitable for checking against the browser's same-origin policy.
Replaces all existing definitions of a parameter with a single definition.
Repeated calls to this can exhibit quadratic behavior due to the need to
find existing instances and reconstruct the string, though it should be
limited given the 2kb limit. Consider using appendParams to append multiple
parameters in bulk.
Each component still URI-encoded.
Each component that is present will contain the encoded value, whereas
components that are not present will be undefined or empty, depending
on the browser's regular expression implementation. Never null, since
arbitrary strings may still look like path names.
Safari has a nasty bug where if you have an http URL with a username, e.g.,
http://evil.com%2F@google.com/
Safari will report that window.location.href is
http://evil.com/google.com/
so that anyone who tries to parse the domain of that URL will get
the wrong domain. We've seen exploits where people use this to trick
Safari into loading resources from evil domains.
To work around this, we run a little "Safari phishing check", and throw
an exception if we see this happening.
There is no convenient place to put this check. We apply it to
anyone doing URI parsing on Webkit. We're not happy about this, but
it fixes the problem.
This should be removed once Safari fixes their bug.
Exploit reported by Masato Kinugawa.
A regular expression for breaking a URI into its component parts.
http://www.ietf.org/rfc/rfc3986.txt says in Appendix B
As the "first-match-wins" algorithm is identical to the "greedy"
disambiguation method used by POSIX regular expressions, it is natural and
commonplace to use a regular expression for parsing the potential five
components of a URI reference.
The following line is the regular expression for breaking-down a
well-formed URI reference into its components.
The numbers in the second line above are only to assist readability; they
indicate the reference points for each subexpression (i.e., each paired
parenthesis). We refer to the value matched for subexpression as $.
For example, matching the above expression to
where indicates that the component is not present, as is the
case for the query component in the above example. Therefore, we can
determine the value of the five components as