- OpenTofu 语言
- 函数
- urlencode
urlencode
函数
urlencode
对给定字符串应用 URL 编码。
此函数识别给定字符串中在 URL 中作为查询字符串参数包含时具有特殊含义的字符,并使用 RFC 3986“百分比编码” 对其进行转义。
转义的字符集可能随着时间的推移而发生变化,但结果保证可以插入到查询字符串参数中,而不会无意中引入额外的分隔符。
如果给定字符串包含非 ASCII 字符,则首先将其编码为 UTF-8,然后分别对每个 UTF-8 字节应用百分比编码。
示例
> urlencode("Hello World!")
Hello+World%21
> urlencode("☃")
%E2%98%83
> "http://example.com/search?q=${urlencode("tofu urlencode")}"
http://example.com/search?q=tofu+urlencode