Learn R Programming

punycoder (version 1.1.0)

url_encode: Encode URLs with Unicode domains to ASCII

Description

Converts URLs containing Unicode domain names to their ASCII representation while preserving the rest of the URL structure. This function is essential for preparing URLs for systems that require ASCII-only domain names.

Usage

url_encode(url, strict = getOption("punycoder.strict", TRUE))

Value

A character vector the same length as url, with each element containing the URL with its host portion ASCII-encoded. Only the domain component is transformed; scheme, path, query, and fragment are preserved. Elements corresponding to NA inputs are NA_character_.

Arguments

url

Character vector of URLs with potential Unicode domains

strict

Logical; whether to apply strict validation. Defaults to `getOption("punycoder.strict", TRUE)`.

See Also

url_decode for the reverse operation, puny_encode for domain-only encoding, parse_url for URL component extraction.

Examples

Run this code
# \donttest{
# Basic URL encoding
url_encode("https://caf\u00E9.example.com/path?query=value")
url_encode(
  "https://\u043C\u043E\u0441\u043A\u0432\u0430.\u0440\u0444/page"
)

# Vectorized URL encoding
urls <- c(
  "https://caf\u00E9.com/menu",
  "https://\u5317\u4EAC.\u4E2D\u56FD/info"
)
url_encode(urls)
# }

Run the code above in your browser using DataLab