简体   繁体   English

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

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

In my html, I have below form:在我的 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>

After inputing " aaa += " and clicking the button, in my cgi-bin/encry.sh, the QUERY_STRING is assigned as "aaa++=" rather than "aaa +=", nor "a+%2B%3D".输入“ aaa += ”并单击按钮后,在我的 cgi-bin/encry.sh 中,QUERY_STRING 被分配为“aaa++=”而不是“aaa +=”,也不是“a+%2B%3D”。 Is that correct behavior, and if so how can I get the blank space correctly?这是正确的行为,如果是这样,我怎样才能正确地获得空格? If not, is that fixed in any later CGIHTTPServer version?如果没有,是否在任何更高版本的 CGIHTTPServer 中修复?

Below provides some info about CGIHTTPServer.py in my CentOS 7.2:下面提供了有关我的 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

Thanks in advance!提前致谢!

After trying the CGIHTTPServer from python2.7.18, I think the asked question is a known issue in 2.7.5, which was my version, and not sure which version fixed it.在从 python2.7.18 尝试 CGIHTTPServer 之后,我认为提出的问题是 2.7.5 中的一个已知问题,这是我的版本,不确定哪个版本修复了它。

The problem is in:问题在于:

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

In 2.7.18, the QUERY_STRING isn't decoded by CGIHTTPServer, and I need to decode it in my CGI script, but that's OK as it's "correct" encoded QUERY_STRING.在 2.7.18 中,QUERY_STRING 不是由 CGIHTTPServer 解码的,我需要在我的 CGI 脚本中对其进行解码,但这没关系,因为它是“正确”编码的 QUERY_STRING。

BTW, I didn't upgrade my python in OS from 2.7.5 to 2.7.18, but just extract CGIHTTPServer from python 2.7.18 source code and use it as:顺便说一句,我没有将操作系统中的 python 从 2.7.5 升级到 2.7.18,而是从 python 2.7.18 源代码中提取 CGIHTTPServer 并将其用作:

nohup python ./CGIHTTPServer.py 7070 & nohup python ./CGIHTTPServer.py 7070 &

rather than而不是

nohup python -m CGIHTTPServer 7070 & nohup python -m CGIHTTPServer 7070 &

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

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