rclone/vendor/github.com/yunify/qingstor-sdk-go/v3/utils/escape.go
2019-08-14 16:15:34 +01:00

23 lines
650 B
Go

package utils
import (
"net/url"
"strings"
)
// URLQueryEscape escapes the original string.
func URLQueryEscape(origin string) string {
escaped := url.QueryEscape(origin)
escaped = strings.Replace(escaped, "%2F", "/", -1)
escaped = strings.Replace(escaped, "%3D", "=", -1)
escaped = strings.Replace(escaped, "+", "%20", -1)
return escaped
}
// URLQueryUnescape unescapes the escaped string.
func URLQueryUnescape(escaped string) (string, error) {
escaped = strings.Replace(escaped, "/", "%2F", -1)
escaped = strings.Replace(escaped, "=", "%3D", -1)
escaped = strings.Replace(escaped, "%20", " ", -1)
return url.QueryUnescape(escaped)
}