mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
http: replace escape() with escape_url()
This commit is contained in:
parent
550e8cd0cb
commit
d3d4ee6b39
2
test.sh
2
test.sh
@ -5,7 +5,7 @@ for f in `find . -type f -name '*_test.v'`; do
|
||||
v $f || echo "fail"
|
||||
done
|
||||
|
||||
for f in examples/*.v ; do
|
||||
for f in `find examples -type f -name '*.v'`; do
|
||||
echo "Building $f..."
|
||||
v $f || echo "fail"
|
||||
done
|
||||
|
@ -189,14 +189,24 @@ pub fn (req &Request) do() Response {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unescape(s string) string {
|
||||
pub fn unescape_url(s string) string {
|
||||
return string(byteptr(C.curl_unescape(s.str, s.len)))
|
||||
}
|
||||
|
||||
pub fn escape(s string) string {
|
||||
pub fn escape_url(s string) string {
|
||||
return string(byteptr(C.curl_escape(s.str, s.len)))
|
||||
}
|
||||
|
||||
pub fn unescape(s string) string {
|
||||
panic('http.unescape() was replaced with http.unescape_url()')
|
||||
return ''
|
||||
}
|
||||
|
||||
pub fn escape(s string) string {
|
||||
panic('http.escape() was replaced with http.escape_url()')
|
||||
return ''
|
||||
}
|
||||
|
||||
// ////////////////
|
||||
fn (req &Request) do2() Response {
|
||||
mut resp := Response{}
|
||||
|
@ -2,8 +2,8 @@ import http
|
||||
|
||||
fn test_escape_unescape() {
|
||||
original := 'те ст: т\\%'
|
||||
escaped := http.escape(original)
|
||||
escaped := http.escape_url(original)
|
||||
assert escaped == '%D1%82%D0%B5%20%D1%81%D1%82%3A%20%D1%82%5C%25'
|
||||
unescaped := http.unescape(escaped)
|
||||
unescaped := http.unescape_url(escaped)
|
||||
assert unescaped == original
|
||||
}
|
||||
|
@ -194,19 +194,29 @@ pub fn (req &Request) do() Response {
|
||||
return resp
|
||||
}
|
||||
|
||||
pub fn escape(s string) string {
|
||||
pub fn escape_url(s string) string {
|
||||
mut buf := &u16(malloc(INTERNET_MAX_URL_LENGTH * 2)) // INTERNET_MAX_URL_LENGTH * sizeof(wchar_t)
|
||||
mut nr_chars := INTERNET_MAX_URL_LENGTH
|
||||
res := C.UrlEscape(s.to_wide(), buf, &nr_chars, URL_ESCAPE_PERCENT | URL_ESCAPE_AS_UTF8 | URL_ESCAPE_ASCII_URI_COMPONENT)
|
||||
return string_from_wide2(buf, nr_chars)
|
||||
}
|
||||
|
||||
pub fn unescape(s string) string {
|
||||
pub fn unescape_url(s string) string {
|
||||
mut buf := &u16(malloc(INTERNET_MAX_URL_LENGTH * 2))
|
||||
mut nr_chars := INTERNET_MAX_URL_LENGTH
|
||||
res := C.UrlUnescape(s.to_wide(), &buf, &nr_chars, URL_ESCAPE_AS_UTF8 | URL_ESCAPE_ASCII_URI_COMPONENT)
|
||||
return string_from_wide2(buf, nr_chars)
|
||||
}
|
||||
|
||||
pub fn unescape(s string) string {
|
||||
panic('http.unescape() was replaced with http.unescape_url()')
|
||||
return ''
|
||||
}
|
||||
|
||||
pub fn escape(s string) string {
|
||||
panic('http.escape() was replaced with http.escape_url()')
|
||||
return ''
|
||||
}
|
||||
|
||||
fn C.InternetReadFile(voidptr, voidptr, int, intptr) bool
|
||||
|
||||
|
@ -140,7 +140,7 @@ fn (ctx mut Context) parse_form(s string) {
|
||||
key := keyval[0]
|
||||
val := keyval[1]
|
||||
//println('http form $key => $val')
|
||||
ctx.post_form[key] = http.unescape(val)
|
||||
ctx.post_form[key] = http.unescape_url(val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user