cuelang.org/go@v0.10.1/pkg/net/url.go (about) 1 // Copyright 2019 CUE Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package net 16 17 import ( 18 "net/url" 19 ) 20 21 // PathEscape escapes the string so it can be safely placed inside a URL path 22 // segment, replacing special characters (including /) with %XX sequences as 23 // needed. 24 func PathEscape(s string) string { 25 return url.PathEscape(s) 26 } 27 28 // PathUnescape does the inverse transformation of PathEscape, converting each 29 // 3-byte encoded substring of the form "%AB" into the hex-decoded byte 0xAB. 30 // It returns an error if any % is not followed by two hexadecimal digits. 31 // 32 // PathUnescape is identical to QueryUnescape except that it does not unescape 33 // '+' to ' ' (space). 34 func PathUnescape(s string) (string, error) { 35 return url.PathUnescape(s) 36 } 37 38 // QueryEscape escapes the string so it can be safely placed inside a URL 39 // query. 40 func QueryEscape(s string) string { 41 return url.QueryEscape(s) 42 } 43 44 // QueryUnescape does the inverse transformation of QueryEscape, converting 45 // each 3-byte encoded substring of the form "%AB" into the hex-decoded byte 46 // 0xAB. It returns an error if any % is not followed by two hexadecimal 47 // digits. 48 func QueryUnescape(s string) (string, error) { 49 return url.QueryUnescape(s) 50 }