diff --git a/src/lua/zencode_http.lua b/src/lua/zencode_http.lua index 9df0d90ef..6df98eca7 100644 --- a/src/lua/zencode_http.lua +++ b/src/lua/zencode_http.lua @@ -140,7 +140,12 @@ function is_valid_uri(uri) error("invalid uri, missing scheme in '" .. uri .. "'", 2) end if parsed.authority ~= "" then - local host_error = _is_valid_host(parsed.authority) + local authority_pattern = "^([^:]+):?(%d*)$" + parsed.hostname, parsed.port = parsed.authority:match(authority_pattern) + if parsed.port ~= "" and not tonumber(parsed.port) then + error("invalid port in '" .. parsed.authority .. "'", 2) + end + local host_error = _is_valid_host(parsed.hostname) if host_error then error(host_error, 2) end diff --git a/test/zencode/http.bats b/test/zencode/http.bats index dc9f61945..2c8c91425 100644 --- a/test/zencode/http.bats +++ b/test/zencode/http.bats @@ -287,3 +287,22 @@ EOF save_output 'append_different_values.json' assert_output '{"another_url":"openid-credential-issuer://www.example.com?param1=value1¶m2=1000¶m3=2000¶m4=3000","url":"openid-credential-issuer://www.example.com?param1=value1¶m2=1000¶m3=2000¶m4=3000"}' } + +@test "url with port" { + cat <