summaryrefslogtreecommitdiffstats
path: root/lualib/lua_maps.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-11-12 14:58:29 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-11-19 12:44:14 +0000
commitcb96968b1b705a3cc60658f006a646acc89c9b73 (patch)
treed65503b9134278ff980226d46145bfe6b3b785cc /lualib/lua_maps.lua
parent87cfbe87495476c15aef290fe252888e4b684619 (diff)
downloadrspamd-cb96968b1b705a3cc60658f006a646acc89c9b73.tar.gz
rspamd-cb96968b1b705a3cc60658f006a646acc89c9b73.zip
[Project] Add a simple url encoding function + tests
Diffstat (limited to 'lualib/lua_maps.lua')
-rw-r--r--lualib/lua_maps.lua7
1 files changed, 6 insertions, 1 deletions
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()