commit cb96968: [Project] Add a simple url encoding function + tests
Vsevolod Stakhov
vsevolod at rspamd.com
Sat Nov 19 20:28:12 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-11-12 14:58:29 +0000
URL: https://github.com/rspamd/rspamd/commit/cb96968b1b705a3cc60658f006a646acc89c9b73
[Project] Add a simple url encoding function + tests
---
lualib/lua_maps.lua | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/lualib/lua_maps.lua b/lualib/lua_maps.lua
index 14439f778..b2f8dda92 100644
--- a/lualib/lua_maps.lua
+++ b/lualib/lua_maps.lua
@@ -99,10 +99,15 @@ local rspamd_http = require "rspamd_http"
local ucl = require "ucl"
local function url_encode_string(str)
- -- TODO: implement encoding
+ str = string.gsub(str, "([^%w _%%%-%.~])",
+ function(c) return string.format("%%%02X", string.byte(c)) end)
+ str = string.gsub(str, " ", "+")
return str
end
+assert(url_encode_string('上海+中國') == '%E4%B8%8A%E6%B5%B7%2B%E4%B8%AD%E5%9C%8B')
+assert(url_encode_string('? and the Mysterians') == '%3F+and+the+Mysterians')
+
local function query_external_map(map_config, upstreams, key, callback, task)
local http_method = (map_config.method == 'body' or map_config.method == 'form') and 'POST' or 'GET'
local upstream = upstreams:get_upstream_round_robin()
More information about the Commits
mailing list