URL 百分号编码用 %HH 字节转义表示 UTF-8 文本。本工具遵循 encodeURIComponent 的行为:字母、数字和 -_.!~*'() 保持原样,其他字节(包括 URL 分隔符和非 ASCII 文本)会被转义。
应在组装 URL 前分别编码路径段或查询值,避免空格、&、=、? 和 Unicode 改变 URL 结构。本工具不会解析完整 URL,也不会把 + 当作空格;它会拒绝格式错误的 % 序列,并且编码不等于加密。
# Encoding
printf 'Hello, World!' | jq -sRr @uri
# Output: Hello%2C%20World%21
# Decoding
printf 'Hello%2C%20World%21' | jq -sRr @urid
# Output: Hello, World!
// Encoding
let encoded = encodeURIComponent("Hello, World!");
console.log(encoded);
// Output: Hello%2C%20World%21
// Decoding
let decoded = decodeURIComponent("Hello%2C%20World%21");
console.log(decoded);
// Output: Hello, World!
package main
import (
"fmt"
"net/url"
)
func main() {
// Encoding
encoded := url.QueryEscape("Hello, World!")
fmt.Println(encoded)
// Output: Hello%2C+%21World%21 (QueryEscape uses + for spaces)
// Decoding
decoded, _ := url.QueryUnescape("Hello%2C%20World%21")
fmt.Println(decoded)
// Output: Hello, World!
}
// Encoding
$encoded = urlencode("Hello, World!");
echo $encoded . "\n";
// Output: Hello%2C+%21World%21
// Decoding
$decoded = urldecode("Hello%2C%20World%21");
echo $decoded . "\n";
// Output: Hello, World!