From 270ec1b51ae2ab9afb1e80d173442cb9d0520068 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Tue, 5 Jul 2016 15:40:25 +0300 Subject: [PATCH] Handle port as number in socket.url.build In particular, luasec passes port as number to socket.url.build. Under Lua 5.3 this can lead to '.0' added to port when converting to string, use 'string.format("%d", port)' to avoid that. --- src/url.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/url.lua b/src/url.lua index b59960a..65aaf0a 100644 --- a/src/url.lua +++ b/src/url.lua @@ -193,7 +193,13 @@ function _M.build(parsed) if string.find(authority, ":") then -- IPv6? authority = "[" .. authority .. "]" end - if parsed.port then authority = authority .. ":" .. parsed.port end + local port = parsed.port + if port then + if type(port) == "number" then + port = string.format("%d", port) + end + authority = authority .. ":" .. port + end local userinfo = parsed.userinfo if parsed.user then userinfo = parsed.user