繁体   English   中英

Python CGIHTTPServer 是否将 URL 中的加号(+)解码为空格?

[英]Does Python CGIHTTPServer decode plus sign(+) in URL into blank space?

在我的 html 中,我有以下表格:

<form method=GET action="/cgi-bin/encry.sh"> 
<table nowrap> 
<tr>
<td>Plain Text:</TD>
<TD><input type="text" name="PlainText"></td>
</tr> 
</table>
<input type="submit" value="Encrypt"> 
</form>

输入“ aaa += ”并单击按钮后,在我的 cgi-bin/encry.sh 中,QUERY_STRING 被分配为“aaa++=”而不是“aaa +=”,也不是“a+%2B%3D”。 这是正确的行为,如果是这样,我怎样才能正确地获得空格? 如果没有,是否在任何更高版本的 CGIHTTPServer 中修复?

下面提供了有关我的 CentOS 7.2 中 CGIHTTPServer.py 的一些信息:

HiAccount-4# md5sum /usr/lib64/python2.7/CGIHTTPServer.py
564afe4defc63001f236b0b2ef899b58  /usr/lib64/python2.7/CGIHTTPServer.py
HiAccount-4# grep __version /usr/lib64/python2.7/CGIHTTPServer.py -i
__version__ = "0.4"
HiAccount-4# grep unquote /usr/lib64/python2.7/CGIHTTPServer.py -i -C 3 -n
84-        path begins with one of the strings in self.cgi_directories
85-        (and the next character is a '/' or the end of the string).
86-        """
87:        collapsed_path = _url_collapse_path(urllib.unquote(self.path))
88-        dir_sep = collapsed_path.find('/', 1)
89-        head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
90-        if head in self.cgi_directories:
--
164-        env['SERVER_PROTOCOL'] = self.protocol_version
165-        env['SERVER_PORT'] = str(self.server.server_port)
166-        env['REQUEST_METHOD'] = self.command
167:        uqrest = urllib.unquote(rest)
168-        env['PATH_INFO'] = uqrest
169-        env['PATH_TRANSLATED'] = self.translate_path(uqrest)
170-        env['SCRIPT_NAME'] = scriptname

提前致谢!

在从 python2.7.18 尝试 CGIHTTPServer 之后,我认为提出的问题是 2.7.5 中的一个已知问题,这是我的版本,不确定哪个版本修复了它。

问题在于:

/usr/lib64/python2.7/CGIHTTPServer.py:87:collapsed_pa​​th = _url_collapse_path(urllib的引文结束(self.path))

在 2.7.18 中,QUERY_STRING 不是由 CGIHTTPServer 解码的,我需要在我的 CGI 脚本中对其进行解码,但这没关系,因为它是“正确”编码的 QUERY_STRING。

顺便说一句,我没有将操作系统中的 python 从 2.7.5 升级到 2.7.18,而是从 python 2.7.18 源代码中提取 CGIHTTPServer 并将其用作:

nohup python ./CGIHTTPServer.py 7070 &

而不是

nohup python -m CGIHTTPServer 7070 &

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM