From 8fcbdb39feb7922a2a6b8bd5cf16aca90e93a624 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 5 Jul 2008 20:12:24 +0000 Subject: [PATCH] * luci/libs: make treatment of "+" conditional in http.protocol ("+" should not be decoded by urldecode) * luci/https: fix breakage introduced by "+" decoding --- libs/http/luasrc/http/protocol.lua | 7 +++++-- libs/httpd/luasrc/httpd/handler/file.lua | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libs/http/luasrc/http/protocol.lua b/libs/http/luasrc/http/protocol.lua index a187bed2e..b8e962449 100644 --- a/libs/http/luasrc/http/protocol.lua +++ b/libs/http/luasrc/http/protocol.lua @@ -23,14 +23,17 @@ HTTP_URLENC_MAXKEYLEN = 1024 -- maximum allowd size of urlencoded parameter nam -- Decode an urlencoded string. -- Returns the decoded value. -function urldecode( str ) +function urldecode( str, no_plus ) local function __chrdec( hex ) return string.char( tonumber( hex, 16 ) ) end if type(str) == "string" then - str = str:gsub( "+", " " ) + if not no_plus then + str = str:gsub( "+", " " ) + end + str = str:gsub( "%%([a-fA-F0-9][a-fA-F0-9])", __chrdec ) end diff --git a/libs/httpd/luasrc/httpd/handler/file.lua b/libs/httpd/luasrc/httpd/handler/file.lua index db8a476d4..92cf7ed0a 100644 --- a/libs/httpd/luasrc/httpd/handler/file.lua +++ b/libs/httpd/luasrc/httpd/handler/file.lua @@ -44,7 +44,7 @@ function Simple.getfile(self, uri) end function Simple.handle_get(self, request, sourcein, sinkerr) - local file, stat = self:getfile( self.proto.urldecode( request.env.PATH_INFO ) ) + local file, stat = self:getfile( self.proto.urldecode( request.env.PATH_INFO, true ) ) if stat then if stat.type == "regular" then @@ -95,7 +95,7 @@ function Simple.handle_get(self, request, sourcein, sinkerr) elseif stat.type == "directory" then local ruri = request.request_uri:gsub("/$","") - local duri = self.proto.urldecode( ruri ) + local duri = self.proto.urldecode( ruri, true ) local root = self.docroot:gsub("/$","") -- check for index files -- 2.25.1