Global

Methods

encodeAbsoluteURI(uri) → {string}

Encodes the pathname of an absolute URI string using encodeURIPath, preserving any query parameters, hash, or trailing slash formatting.

Parameters:
Name Type Description
uri string

The absolute URI string to encode.

Returns:
Type Description
string

The formatted and encoded absolute URI string.

encodeURIPath(uri) → {string}

Encodes each path segment in a URI string while preserving slash (/) and colon (:) delimiters, and validates that no path segment is . or .. to prevent path traversal.

Parameters:
Name Type Description
uri string

The URI path to encode.

Returns:
Type Description
string

The encoded URI path.

encodeWithSlashes(str) → {string}

Percent-encodes a string according to RFC 3986, preserving only unreserved characters (alpha-numeric, '-', '_', '.', and '~'). All other characters, including slashes ('/'), are percent-encoded.

This is necessary because encodeURIComponent natively encodes URL-unsafe characters like ?, #, $, &, +, etc., but preserves !, ', (, ), and *. To ensure strict compliance, we manually encode those preserved characters.

This method is a replica of the method found in Google GAX (google-gax).

Parameters:
Name Type Description
str string

The input string to encode.

Returns:
Type Description
string

The percent-encoded string.

encodeWithoutSlashes(str) → {string}

Percent-encodes a string according to RFC 3986, preserving unreserved characters (alpha-numeric, '-', '_', '.', and '~') and slashes ('/'). All other characters are percent-encoded.

This method is a replica of the method found in Google GAX (google-gax).

Parameters:
Name Type Description
str string

The input string to encode.

Returns:
Type Description
string

The percent-encoded string with slashes preserved.

joinURIComponents(components) → {string}

Trims slashes, encodes path segments to prevent path traversal, and joins URI components into a single relative path.

Parameters:
Name Type Description
components Array.<string>

URI components to encode and join.

Returns:
Type Description
string

The formatted and joined URI path.

validateUriPath(propertyName, value)

Validates a multi-segment path matched by a double wildcard (**). Splitting by slash, it checks that no individual segment is exactly '.' or '..'. This segment-by-segment check prevents directory traversal while allowing legitimate resource names containing dots (e.g., domain-scoped project IDs).

This method is a replica of the method found in Google GAX (google-gax).

Parameters:
Name Type Description
propertyName string

The name of the property being validated.

value string

The path value to validate.

validateUriPathSegment(propertyName, value)

Validates a single path segment matched by a single wildcard (*). Checks that the segment is not exactly '.' or '..' (directory traversal indicators).

This method is a replica of the method found in Google GAX (google-gax).

Parameters:
Name Type Description
propertyName string

The name of the property being validated.

value string

The segment value to validate.