1.31 <GUri>

Structure: <GUri>

The <GUri> type and related functions can be used to parse URIs into their components, and build valid URIs from individual components.

Since <GUri> only represents absolute URIs, all <GUri>s will have a URI scheme, so uri:get-scheme will always return a non-NULL answer. Likewise, by definition, all URIs have a path component, so uri:get-path will always return a non-NULL string (which may be empty).

If the URI string has an ‘authority’ component (that is, if the scheme is followed by :// rather than just :), then the <GUri> will contain a hostname, and possibly a port and ‘userinfo’. Additionally, depending on how the <GUri> was constructed/parsed (for example, using the has-password and has-auth-params flags), the userinfo may be split out into a username, password, and additional authorization-related parameters.

Normally, the components of a <GUri> will have all %-encoded characters decoded. However, if you construct/parse a <GUri> with encoded, then the %-encoding will be preserved instead in the userinfo, path, and query fields (and in the host field if also created with non-dns). In particular, this is necessary if the URI may contain binary data or non-UTF-8 text, or if decoding the components might change the interpretation of the URI.

For example, with the encoded flag:

g_autoptr(GUri) uri = g_uri_parse ("http://host/path?query=http%3A%2F%2Fhost%2Fpath%3Fparam%3Dvalue", G_URI_FLAGS_ENCODED, &err);
g_assert_cmpstr (g_uri_get_query (uri), ==, "query=http%3A%2F%2Fhost%2Fpath%3Fparam%3Dvalue");

While the default %-decoding behaviour would give:

g_autoptr(GUri) uri = g_uri_parse ("http://host/path?query=http%3A%2F%2Fhost%2Fpath%3Fparam%3Dvalue", G_URI_FLAGS_NONE, &err);
g_assert_cmpstr (g_uri_get_query (uri), ==, "query=http://host/path?param=value");

During decoding, if an invalid UTF-8 string is encountered, parsing will fail with an error indicating the bad string location:

g_autoptr(GUri) uri = g_uri_parse ("http://host/path?query=http%3A%2F%2Fhost%2Fpath%3Fbad%3D%00alue", G_URI_FLAGS_NONE, &err);
g_assert_error (err, G_URI_ERROR, G_URI_ERROR_BAD_QUERY);

You should pass encoded or encoded-query if you need to handle that case manually. In particular, if the query string contains = characters that are %-encoded, you should let uri:parse-params do the decoding once of the query.

<GUri> is immutable once constructed, and can safely be accessed from multiple threads. Its reference counting is atomic.

Note that the scope of <GUri> is to help manipulate URIs in various applications, following RFC 3986. In particular, it doesn’t intend to cover web browser needs, and doesn’t implement the WHATWG URL standard. No APIs are provided to help prevent homograph attacks, so <GUri> is not suitable for formatting URIs for display to the user for making security-sensitive decisions.

Relative and absolute URIs

As defined in RFC 3986, the hierarchical nature of URIs means that they can either be ‘relative references’ (sometimes referred to as ‘relative URIs’) or ‘URIs’ (for clarity, ‘URIs’ are referred to in this documentation as ‘absolute URIs’ — although in contrast to RFC 3986, fragment identifiers are always allowed).

Relative references have one or more components of the URI missing. In particular, they have no scheme. Any other component, such as hostname, query, etc. may be missing, apart from a path, which has to be specified (but may be empty). The path may be relative, starting with ./ rather than /.

For example, a valid relative reference is ./path?query, /?query#fragment or //example.com.

Absolute URIs have a scheme specified. Any other components of the URI which are missing are specified as explicitly unset in the URI, rather than being resolved relative to a base URI using uri:parse-relative.

For example, a valid absolute URI is file:///home/bob or https://search.com?query=string.

A <GUri> instance is always an absolute URI. A string may be an absolute URI or a relative reference; see the documentation for individual functions as to what forms they accept.

Parsing URIs

The most minimalist APIs for parsing URIs are uri:split and uri:split-with-user. These split a URI into its component parts, and return the parts; the difference between the two is that uri:split treats the ‘userinfo’ component of the URI as a single element, while uri:split-with-user can (depending on the <%GUriFlags> you pass) treat it as containing a username, password, and authentication parameters. Alternatively, uri:split-network can be used when you are only interested in the components that are needed to initiate a network connection to the service (scheme, host, and port).

uri:parse is similar to uri:split, but instead of returning individual strings, it returns a <GUri> structure (and it requires that the URI be an absolute URI).

uri:resolve-relative and uri:parse-relative allow you to resolve a relative URI relative to a base URI. uri:resolve-relative takes two strings and returns a string, and uri:parse-relative takes a <GUri> and a string and returns a <GUri>.

All of the parsing functions take a <%GUriFlags> argument describing exactly how to parse the URI; see the documentation for that type for more details on the specific flags that you can pass. If you need to choose different flags based on the type of URI, you can use uri:peek-scheme on the URI string to check the scheme first, and use that to decide what flags to parse it with.

For example, you might want to use www-form when parsing the params for a web URI, so compare the result of uri:peek-scheme against http and https.

Building URIs

uri:join and uri:join-with-user can be used to construct valid URI strings from a set of component strings. They are the inverse of uri:split and uri:split-with-user.

Similarly, uri:build and uri:build-with-user can be used to construct a <GUri> from a set of component strings.

As with the parsing functions, the building functions take a <%GUriFlags> argument. In particular, it is important to keep in mind whether the URI components you are using are already %-encoded. If so, you must pass the encoded flag.

‘file://‘ URIs

Note that Windows and Unix both define special rules for parsing file:// URIs (involving non-UTF-8 character sets on Unix, and the interpretation of path separators on Windows). <GUri> does not implement these rules. Use filename-from-uri and filename-to-uri if you want to properly convert between file:// URIs and local filenames.

URI Equality

Note that there is no g_uri_equal () function, because comparing URIs usefully requires scheme-specific knowledge that <GUri> does not have. <GUri> can help with normalization if you use the various encoded <%GUriFlags> as well as scheme-normalize however it is not comprehensive. For example, data:,foo and data:;base64,Zm9v resolve to the same thing according to the data: URI specification which GLib does not handle.

Procedures

Procedure: uri:build flags scheme userinfo host port path [query] [fragment] ⇒ %return

Creates a new <GUri> from the given components according to flags.

See also uri-build-with-user, which allows specifying the components of the "userinfo" separately.

flags

Passed: a <%GUriFlags>, or a list of its symbols, or one of them.

flags describing how to build the <GUri>

scheme

Passed: a string.

the URI scheme

userinfo

Passed: a string, or #f.

the userinfo component, or #f

host

Passed: a string, or #f.

the host component, or #f

port

Passed: a 32-bit integer.

the port, or -1

path

Passed: a string.

the path component

query

Passed, or left out: a string, or #f.

the query component, or #f

fragment

Passed, or left out: a string, or #f.

the fragment, or #f

%return

Returned: a <GUri>.

a new <GUri>

Procedure: uri:build-with-user flags scheme user password auth-params host port path [query] [fragment] ⇒ %return

Creates a new <GUri> from the given components according to flags (has-password is added unconditionally). The flags must be coherent with the passed values, in particular use %-encoded values with encoded.

In contrast to uri-build, this allows specifying the components of the ‘userinfo’ field separately. Note that user must be non-#f if either password or auth-params is non-#f.

flags

Passed: a <%GUriFlags>, or a list of its symbols, or one of them.

flags describing how to build the <GUri>

scheme

Passed: a string.

the URI scheme

user

Passed: a string, or #f.

the user component of the userinfo, or #f

password

Passed: a string, or #f.

the password component of the userinfo, or #f

auth-params

Passed: a string, or #f.

the auth params of the userinfo, or #f

host

Passed: a string, or #f.

the host component, or #f

port

Passed: a 32-bit integer.

the port, or -1

path

Passed: a string.

the path component

query

Passed, or left out: a string, or #f.

the query component, or #f

fragment

Passed, or left out: a string, or #f.

the fragment, or #f

%return

Returned: a <GUri>.

a new <GUri>

Procedure: uri:error-quark ⇒ %return
%return

Returned: an unsigned 32-bit integer.

Procedure: uri:escape-bytes unescaped [reserved-chars-allowed] ⇒ %return

Escapes arbitrary data for use in a URI.

Normally all characters that are not ‘unreserved’ (i.e. ASCII alphanumerical characters plus dash, dot, underscore and tilde) are escaped. But if you specify characters in reserved-chars-allowed they are not escaped. This is useful for the ‘reserved’ characters in the URI specification, since those are allowed unescaped in some portions of a URI.

Though technically incorrect, this will also allow escaping nul bytes as %00.

unescaped

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.

the unescaped input data.

reserved-chars-allowed

Passed, or left out: a string, or #f.

a string of reserved characters that are allowed to be used, or #f.

%return

Returned: a string.

an escaped version of unescaped. The returned string should be freed when no longer needed.

length

Not passed: guile-gi gives the length of unescaped.

the length of unescaped

Procedure: uri:escape-string unescaped reserved-chars-allowed allow-utf8 ⇒ %return

Escapes a string for use in a URI.

Normally all characters that are not "unreserved" (i.e. ASCII alphanumerical characters plus dash, dot, underscore and tilde) are escaped. But if you specify characters in reserved-chars-allowed they are not escaped. This is useful for the "reserved" characters in the URI specification, since those are allowed unescaped in some portions of a URI.

unescaped

Passed: a string.

the unescaped input string.

reserved-chars-allowed

Passed: a string, or #f.

a string of reserved characters that are allowed to be used, or #f.

allow-utf8

Passed: a boolean.

#t if the result can include UTF-8 characters.

%return

Returned: a string.

an escaped version of unescaped. The returned string should be freed when no longer needed.

Method: uri:get-auth-params self ⇒ %return
Method: get-auth-params self ⇒ %return

Gets self’s authentication parameters, which may contain %-encoding, depending on the flags with which self was created. (If self was not created with has-auth-params then this will be #f.)

Depending on the URI scheme, uri-parse-params may be useful for further parsing this information.

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a string, or #f.

self’s authentication parameters.

Method: uri:get-flags self ⇒ %return
Method: get-flags self ⇒ %return

Gets self’s flags set upon construction.

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a <%GUriFlags>.

self’s flags.

Method: uri:get-fragment self ⇒ %return
Method: get-fragment self ⇒ %return

Gets self’s fragment, which may contain %-encoding, depending on the flags with which self was created.

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a string, or #f.

self’s fragment.

Method: uri:get-host self ⇒ %return
Method: get-host self ⇒ %return

Gets self’s host. This will never have %-encoded characters, unless it is non-UTF-8 (which can only be the case if self was created with non-dns).

If self contained an IPv6 address literal, this value will be just that address, without the brackets around it that are necessary in the string form of the URI. Note that in this case there may also be a scope ID attached to the address. Eg, fe80::1234%em1 (or fe80::1234%25em1 if the string is still encoded).

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a string, or #f.

self’s host.

Method: uri:get-password self ⇒ %return
Method: get-password self ⇒ %return

Gets self’s password, which may contain %-encoding, depending on the flags with which self was created. (If self was not created with has-password then this will be #f.)

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a string, or #f.

self’s password.

Method: uri:get-path self ⇒ %return
Method: get-path self ⇒ %return

Gets self’s path, which may contain %-encoding, depending on the flags with which self was created.

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a string.

self’s path.

Method: uri:get-port self ⇒ %return
Method: get-port self ⇒ %return

Gets self’s port.

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a 32-bit integer.

self’s port, or -1 if no port was specified.

Method: uri:get-query self ⇒ %return
Method: get-query self ⇒ %return

Gets self’s query, which may contain %-encoding, depending on the flags with which self was created.

For queries consisting of a series of name=value parameters, GUriParamsIter or uri-parse-params may be useful.

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a string, or #f.

self’s query.

Method: uri:get-scheme self ⇒ %return
Method: get-scheme self ⇒ %return

Gets self’s scheme. Note that this will always be all-lowercase, regardless of the string or strings that self was created from.

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a string.

self’s scheme.

Method: uri:get-user self ⇒ %return
Method: get-user self ⇒ %return

Gets the ‘username’ component of self’s userinfo, which may contain %-encoding, depending on the flags with which self was created. If self was not created with has-password or has-auth-params, this is the same as uri:get-userinfo.

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a string, or #f.

self’s user.

Method: uri:get-userinfo self ⇒ %return
Method: get-userinfo self ⇒ %return

Gets self’s userinfo, which may contain %-encoding, depending on the flags with which self was created.

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a string, or #f.

self’s userinfo.

Procedure: uri:is-valid? uri-string flags ⇒ %return

Parses uri-string according to flags, to determine whether it is a valid absolute URI, i.e. it does not need to be resolved relative to another URI using uri:parse-relative.

If it’s not a valid URI, an error is returned explaining how it’s invalid.

See uri-split, and the definition of <%GUriFlags>, for more information on the effect of flags.

uri-string

Passed: a string.

a string containing an absolute URI

flags

Passed: a <%GUriFlags>, or a list of its symbols, or one of them.

flags for parsing uri-string

%return

Returned: a boolean.

#t if uri-string is a valid absolute URI, #f on error.

Procedure: uri:join flags scheme userinfo host port path [query] [fragment] ⇒ %return

Joins the given components together according to flags to create an absolute URI string. path may not be #f (though it may be the empty string).

When host is present, path must either be empty or begin with a slash (/) character. When host is not present, path cannot begin with two slash characters (//). See section 3.

See also uri-join-with-user, which allows specifying the components of the ‘userinfo’ separately.

has-password and has-auth-params are ignored if set in flags.

flags

Passed: a <%GUriFlags>, or a list of its symbols, or one of them.

flags describing how to build the URI string

scheme

Passed: a string, or #f.

the URI scheme, or #f

userinfo

Passed: a string, or #f.

the userinfo component, or #f

host

Passed: a string, or #f.

the host component, or #f

port

Passed: a 32-bit integer.

the port, or -1

path

Passed: a string.

the path component

query

Passed, or left out: a string, or #f.

the query component, or #f

fragment

Passed, or left out: a string, or #f.

the fragment, or #f

%return

Returned: a string.

an absolute URI string

Procedure: uri:join-with-user flags scheme user password auth-params host port path [query] [fragment] ⇒ %return

Joins the given components together according to flags to create an absolute URI string. path may not be #f (though it may be the empty string).

In contrast to uri-join, this allows specifying the components of the ‘userinfo’ separately. It otherwise behaves the same.

has-password and has-auth-params are ignored if set in flags.

flags

Passed: a <%GUriFlags>, or a list of its symbols, or one of them.

flags describing how to build the URI string

scheme

Passed: a string, or #f.

the URI scheme, or #f

user

Passed: a string, or #f.

the user component of the userinfo, or #f

password

Passed: a string, or #f.

the password component of the userinfo, or #f

auth-params

Passed: a string, or #f.

the auth params of the userinfo, or #f

host

Passed: a string, or #f.

the host component, or #f

port

Passed: a 32-bit integer.

the port, or -1

path

Passed: a string.

the path component

query

Passed, or left out: a string, or #f.

the query component, or #f

fragment

Passed, or left out: a string, or #f.

the fragment, or #f

%return

Returned: a string.

an absolute URI string

Procedure: uri:list-extract-uris uri-list ⇒ %return

Splits an URI list conforming to the text/uri-list mime type defined in RFC 2483 into individual URIs, discarding any comments. The URIs are not validated.

uri-list

Passed: a string.

an URI list

%return

Returned: a vector, each a string.

a newly allocated #f-terminated list of strings holding the individual URIs. The array should be freed with strfreev.

Procedure: uri:parse uri-string flags ⇒ %return

Parses uri-string according to flags. If the result is not a valid absolute URI, it will be discarded, and an error returned.

uri-string

Passed: a string.

a string representing an absolute URI

flags

Passed: a <%GUriFlags>, or a list of its symbols, or one of them.

flags describing how to parse uri-string

%return

Returned: a <GUri>.

a new <GUri>, or NULL on error.

Procedure: uri:parse-params params length separators flags ⇒ %return

Many URI schemes include one or more attribute/value pairs as part of the URI value. This method can be used to parse them into a hash table. When an attribute has multiple occurrences, the last value is the final returned value. If you need to handle repeated attributes differently, use GUriParamsIter.

The params string is assumed to still be %-encoded, but the returned values will be fully decoded. (Thus it is possible that the returned values may contain = or separators, if the value was encoded in the input.) Invalid %-encoding is treated as with the parse-relaxed rules for uri-parse. (However, if params is the path or query string from a <GUri> that was parsed without parse-relaxed and encoded, then you already know that it does not contain any invalid encoding.)

www-form is handled as documented for g_uri_params_iter_init().

If case-insensitive is passed to flags, attributes will be compared case-insensitively, so a params string attr=123&Attr=456 will only return a single attribute–value pair, Attr=456. Case will be preserved in the returned attributes.

If params cannot be parsed (for example, it contains two separators characters in a row), then error is set and #f is returned.

params

Passed: a string.

a %-encoded string containing attribute=value parameters

length

Passed: a 64-bit integer.

the length of params, or -1 if it is nul-terminated

separators

Passed: a string.

the separator byte character set between parameters. (usually &, but sometimes ; or both &;). Note that this function works on bytes not characters, so it can’t be used to delimit UTF-8 strings for anything but ASCII characters. You may pass an empty set, in which case no splitting will occur.

flags

Passed: a <%GUriParamsFlags>, or a list of its symbols, or one of them.

flags to modify the way the parameters are handled.

%return

Returned: a hash table, each key a string and each value a string.

A hash table of attribute/value pairs, with both names and values fully-decoded; or #f on error.

Method: uri:parse-relative self uri-ref flags ⇒ %return
Method: parse-relative self uri-ref flags ⇒ %return

Parses uri-ref according to flags and, if it is a relative URI, resolves it relative to self. If the result is not a valid absolute URI, it will be discarded, and an error returned.

self

Passed: a <GUri>.

a base absolute URI

uri-ref

Passed: a string.

a string representing a relative or absolute URI

flags

Passed: a <%GUriFlags>, or a list of its symbols, or one of them.

flags describing how to parse uri-ref

%return

Returned: a <GUri>.

a new <GUri>, or NULL on error.

Procedure: uri:parse-scheme uri ⇒ %return

Gets the scheme portion of a URI string. RFC 3986 decodes the scheme as:


URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

Common schemes include file, https, svn+ssh, etc.

uri

Passed: a string.

a valid URI.

%return

Returned: a string, or #f.

The ‘scheme’ component of the URI, or #f on error. The returned string should be freed when no longer needed.

Procedure: uri:peek-scheme uri ⇒ %return

Gets the scheme portion of a URI string. RFC 3986 decodes the scheme as:


URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

Common schemes include file, https, svn+ssh, etc.

Unlike uri-parse-scheme, the returned scheme is normalized to all-lowercase and does not need to be freed.

uri

Passed: a string.

a valid URI.

%return

Returned: a string, or #f.

The ‘scheme’ component of the URI, or #f on error. The returned string is normalized to all-lowercase, and interned via intern-string, so it does not need to be freed.

Procedure: uri:resolve-relative base-uri-string uri-ref flags ⇒ %return

Parses uri-ref according to flags and, if it is a relative URI, resolves it relative to base-uri-string. If the result is not a valid absolute URI, it will be discarded, and an error returned.

(If base-uri-string is #f, this just returns uri-ref, or #f if uri-ref is invalid or not absolute.)

base-uri-string

Passed: a string, or #f.

a string representing a base URI

uri-ref

Passed: a string.

a string representing a relative or absolute URI

flags

Passed: a <%GUriFlags>, or a list of its symbols, or one of them.

flags describing how to parse uri-ref

%return

Returned: a string.

the resolved URI string, or NULL on error.

Procedure: uri:split uri-ref flags ⇒ scheme userinfo host port path query fragment

Parses uri-ref (which can be an absolute or relative URI) according to flags, and returns the pieces. Any component that doesn’t appear in uri-ref will be returned as #f (but note that all URIs always have a path component, though it may be the empty string).

If flags contains encoded, then %-encoded characters in uri-ref will remain encoded in the output strings. (If not, then all such characters will be decoded.) Note that decoding will only work if the URI components are ASCII or UTF-8, so you will need to use encoded if they are not.

Note that the has-password and has-auth-params flags are ignored by uri-split, since it always returns only the full userinfo; use uri-split-with-user if you want it split up.

uri-ref

Passed: a string.

a string containing a relative or absolute URI

flags

Passed: a <%GUriFlags>, or a list of its symbols, or one of them.

flags for parsing uri-ref

scheme

Returned: a string, or #f.

on return, contains the scheme (converted to lowercase), or #f

userinfo

Returned: a string, or #f.

on return, contains the userinfo, or #f

host

Returned: a string, or #f.

on return, contains the host, or #f

port

Returned: a 32-bit integer.

on return, contains the port, or -1

path

Returned: a string.

on return, contains the path

query

Returned: a string, or #f.

on return, contains the query, or #f

fragment

Returned: a string, or #f.

on return, contains the fragment, or #f

Procedure: uri:split-network uri-string flags ⇒ scheme host port

Parses uri-string (which must be an absolute URI) according to flags, and returns the pieces relevant to connecting to a host. See the documentation for uri-split for more details; this is mostly a wrapper around that function with simpler arguments. However, it will return an error if uri-string is a relative URI, or does not contain a hostname component.

uri-string

Passed: a string.

a string containing an absolute URI

flags

Passed: a <%GUriFlags>, or a list of its symbols, or one of them.

flags for parsing uri-string

scheme

Returned: a string, or #f.

on return, contains the scheme (converted to lowercase), or #f

host

Returned: a string, or #f.

on return, contains the host, or #f

port

Returned: a 32-bit integer.

on return, contains the port, or -1

Procedure: uri:split-with-user uri-ref flags ⇒ scheme user password auth-params host port path query fragment

Parses uri-ref (which can be an absolute or relative URI) according to flags, and returns the pieces. Any component that doesn’t appear in uri-ref will be returned as #f (but note that all URIs always have a path component, though it may be the empty string).

See uri-split, and the definition of <%GUriFlags>, for more information on the effect of flags. Note that password will only be parsed out if flags contains has-password, and auth-params will only be parsed out if flags contains has-auth-params.

uri-ref

Passed: a string.

a string containing a relative or absolute URI

flags

Passed: a <%GUriFlags>, or a list of its symbols, or one of them.

flags for parsing uri-ref

scheme

Returned: a string, or #f.

on return, contains the scheme (converted to lowercase), or #f

user

Returned: a string, or #f.

on return, contains the user, or #f

password

Returned: a string, or #f.

on return, contains the password, or #f

auth-params

Returned: a string, or #f.

on return, contains the auth_params, or #f

host

Returned: a string, or #f.

on return, contains the host, or #f

port

Returned: a 32-bit integer.

on return, contains the port, or -1

path

Returned: a string.

on return, contains the path

query

Returned: a string, or #f.

on return, contains the query, or #f

fragment

Returned: a string, or #f.

on return, contains the fragment, or #f

Method: uri:to-string self ⇒ %return
Method: to-string self ⇒ %return

Returns a string representing self.

This is not guaranteed to return a string which is identical to the string that self was parsed from. However, if the source URI was syntactically correct (according to RFC 3986), and it was parsed with encoded, then uri:to-string is guaranteed to return a string which is at least semantically equivalent to the source URI (according to RFC 3986).

If self might contain sensitive details, such as authentication parameters, or private data in its query string, and the returned string is going to be logged, then consider using uri:to-string-partial to redact parts.

self

Passed: a <GUri>.

a <GUri>

%return

Returned: a string.

a string representing self, which the caller must free.

Method: uri:to-string-partial self flags ⇒ %return
Method: to-string-partial self flags ⇒ %return

Returns a string representing self, subject to the options in flags. See uri:to-string and <%GUriHideFlags> for more details.

self

Passed: a <GUri>.

a <GUri>

flags

Passed: a <%GUriHideFlags>, or a list of its symbols, or one of them.

flags describing what parts of self to hide

%return

Returned: a string.

a string representing self, which the caller must free.

Procedure: uri:unescape-bytes escaped-string length [illegal-characters] ⇒ %return

Unescapes a segment of an escaped string as binary data.

Note that in contrast to uri-unescape-string, this does allow nul bytes to appear in the output.

If any of the characters in illegal-characters appears as an escaped character in escaped-string, then that is an error and #f will be returned. This is useful if you want to avoid for instance having a slash being expanded in an escaped path element, which might confuse pathname handling.

escaped-string

Passed: a string.

A URI-escaped string

length

Passed: a 64-bit integer.

the length (in bytes) of escaped-string to escape, or -1 if it is nul-terminated.

illegal-characters

Passed, or left out: a string, or #f.

a string of illegal characters not to be allowed, or #f.

%return

Returned: a <GBytes>.

an unescaped version of escaped-string or #f on error (if decoding failed, using failed error code). The returned <GBytes> should be unreffed when no longer needed.

Procedure: uri:unescape-segment [escaped-string] [escaped-string-end] [illegal-characters] ⇒ %return

Unescapes a segment of an escaped string.

If any of the characters in illegal-characters or the NUL character appears as an escaped character in escaped-string, then that is an error and #f will be returned. This is useful if you want to avoid for instance having a slash being expanded in an escaped path element, which might confuse pathname handling.

Note: NUL byte is not accepted in the output, in contrast to uri-unescape-bytes.

escaped-string

Passed, or left out: a string, or #f.

A string, may be #f

escaped-string-end

Passed, or left out: a string, or #f.

Pointer to end of escaped-string, may be #f

illegal-characters

Passed, or left out: a string, or #f.

An optional string of illegal characters not to be allowed, may be #f

%return

Returned: a string, or #f.

an unescaped version of escaped-string, or #f on error. The returned string should be freed when no longer needed. As a special case if #f is given for escaped-string, this function will return #f.

Procedure: uri:unescape-string escaped-string [illegal-characters] ⇒ %return

Unescapes a whole escaped string.

If any of the characters in illegal-characters or the NUL character appears as an escaped character in escaped-string, then that is an error and #f will be returned. This is useful if you want to avoid for instance having a slash being expanded in an escaped path element, which might confuse pathname handling.

escaped-string

Passed: a string.

an escaped string to be unescaped.

illegal-characters

Passed, or left out: a string, or #f.

a string of illegal characters not to be allowed, or #f.

%return

Returned: a string, or #f.

an unescaped version of escaped-string. The returned string should be freed when no longer needed.