From 332f3a924cefd98169ab158015a4ae4b04581b37 Mon Sep 17 00:00:00 2001 From: Oghogho Odemwingie Date: Sat, 12 Sep 2020 01:31:06 +0100 Subject: [PATCH] builtin: consume matched string length in string.replace_each (#6349) --- vlib/builtin/string.v | 2 +- vlib/builtin/string_test.v | 5 +++++ vlib/net/http/http_httpbin_test.v | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 0dd55187b1..ea9e225302 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -292,7 +292,7 @@ pub fn (s string) replace_each(vals []string) string { idx:idx val_idx:rep_i } - idx++ + idx += rep.len new_len += with.len - rep.len } } diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index fcdd26aaa8..20c8d6b8eb 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -285,6 +285,11 @@ fn test_replace_each() { '[b]', '', '[/b]', '', ]) == 'cool' + t := 'aaaaaaaa' + y := t.replace_each([ + 'aa', 'b' + ]) + assert y == 'bbbb' } fn test_itoa() { diff --git a/vlib/net/http/http_httpbin_test.v b/vlib/net/http/http_httpbin_test.v index 51ec0698bf..cbdfcd009d 100644 --- a/vlib/net/http/http_httpbin_test.v +++ b/vlib/net/http/http_httpbin_test.v @@ -8,7 +8,7 @@ struct HttpbinResponseBody { files map[string]string form map[string]string headers map[string]string - json ?map[string]string + json map[string]string origin string url string } @@ -22,7 +22,7 @@ fn http_fetch_mock(_methods []string, _config FetchConfig) ?[]Response { // Note: httpbin doesn't support head for method in methods { lmethod := method.to_lower() - config.method = method + config.method = method_from_str(method) res := fetch(url + lmethod, config)? // TODO // body := json.decode(HttpbinResponseBody,res.text)?