From d3d4ee6b39ed7dd096da072fcc8fd25414d7c70d Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 31 Jul 2019 20:53:07 +0200 Subject: [PATCH] http: replace escape() with escape_url() --- test.sh | 2 +- vlib/http/http_nix.v | 14 ++++++++++++-- vlib/http/http_test.v | 4 ++-- vlib/http/http_win.v | 14 ++++++++++++-- vlib/vweb/vweb.v | 2 +- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/test.sh b/test.sh index 75e38cf1f5..c81f646289 100644 --- a/test.sh +++ b/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 diff --git a/vlib/http/http_nix.v b/vlib/http/http_nix.v index 8a1f6929ff..bb5a3a18e3 100644 --- a/vlib/http/http_nix.v +++ b/vlib/http/http_nix.v @@ -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{} diff --git a/vlib/http/http_test.v b/vlib/http/http_test.v index 514169f506..9bb3645c67 100644 --- a/vlib/http/http_test.v +++ b/vlib/http/http_test.v @@ -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 } diff --git a/vlib/http/http_win.v b/vlib/http/http_win.v index f322d18afb..ccda9b4e54 100644 --- a/vlib/http/http_win.v +++ b/vlib/http/http_win.v @@ -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 diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 2417c03605..d26f052869 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -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) } } }