Skip to content

Commit

Permalink
[Project] Add a simple url encoding function + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Nov 19, 2022
1 parent 87cfbe8 commit cb96968
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lualib/lua_maps.lua
Expand Up @@ -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()
Expand Down

0 comments on commit cb96968

Please sign in to comment.