Commit 4720da81 authored by Andreas Jung's avatar Andreas Jung

Reworked version of rev 1.49. Fixes a strange problem with the re module in...

Reworked version of rev 1.49. Fixes a strange problem with the re module in Python 2.1c1. Works now with the official 2.1 release
parent e180b0af
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
# #
############################################################################## ##############################################################################
__version__='$Revision: 1.50 $'[11:-2] __version__='$Revision: 1.51 $'[11:-2]
import regex, re, sys, os, string, urllib, time, whrandom import regex, re, sys, os, string, urllib, time, whrandom
from string import lower, atoi, rfind, split, strip, join, upper, find from string import lower, atoi, rfind, split, strip, join, upper, find
...@@ -383,7 +383,7 @@ class HTTPRequest(BaseRequest): ...@@ -383,7 +383,7 @@ class HTTPRequest(BaseRequest):
hasattr=hasattr, hasattr=hasattr,
getattr=getattr, getattr=getattr,
setattr=setattr, setattr=setattr,
search_type=regex.compile('\(:[a-zA-Z][a-zA-Z0-9_]+\|\.[xy]\)$').search, search_type=re.compile('(:[a-zA-Z][a-zA-Z0-9_]+|\\.[xy])$').search,
rfind=string.rfind, rfind=string.rfind,
): ):
"""Process request inputs """Process request inputs
...@@ -450,13 +450,18 @@ class HTTPRequest(BaseRequest): ...@@ -450,13 +450,18 @@ class HTTPRequest(BaseRequest):
# do a string search, and then we'll check it with # do a string search, and then we'll check it with
# a regex search. # a regex search.
l=rfind(key,':') l=rfind(key,':')
if l >= 0: if l >= 0:
l=search_type(key,l) mo = search_type(key,l)
if mo: l=mo.start(0)
else: l=-1
while l >= 0: while l >= 0:
type_name=key[l+1:] type_name=key[l+1:]
key=key[:l] key=key[:l]
c=get_converter(type_name, None) c=get_converter(type_name, None)
if c is not None: if c is not None:
converter=c converter=c
flags=flags|CONVERTED flags=flags|CONVERTED
...@@ -486,7 +491,11 @@ class HTTPRequest(BaseRequest): ...@@ -486,7 +491,11 @@ class HTTPRequest(BaseRequest):
l=rfind(key,':') l=rfind(key,':')
if l < 0: break if l < 0: break
l=search_type(key,l) mo=search_type(key,l)
if mo: l = mo.start(0)
else: l = -1
# Filter out special names from form: # Filter out special names from form:
if CGI_name(key) or key[:5]=='HTTP_': continue if CGI_name(key) or key[:5]=='HTTP_': continue
...@@ -1050,16 +1059,11 @@ class FileUpload: ...@@ -1050,16 +1059,11 @@ class FileUpload:
parse_cookie_lock=allocate_lock() parse_cookie_lock=allocate_lock()
def parse_cookie(text, def parse_cookie(text,
result=None, result=None,
qparmre=regex.compile( qparmre=re.compile(
'\([\0- ]*' '([\x00- ]*([^\x00- ;,="]+)="([^"]*)"([\x00- ]*[;,])?[\x00- ]*)'),
'\([^\0- ;,=\"]+\)="\([^"]*\)\"' parmre=re.compile(
'\([\0- ]*[;,]\)?[\0- ]*\)' '([\x00- ]*([^\x00- ;,="]+)=([^\x00- ;,"]*)([\x00- ]*[;,])?[\x00- ]*)'),
),
parmre=regex.compile(
'\([\0- ]*'
'\([^\0- ;,=\"]+\)=\([^\0- ;,\"]*\)'
'\([\0- ]*[;,]\)?[\0- ]*\)'
),
acquire=parse_cookie_lock.acquire, acquire=parse_cookie_lock.acquire,
release=parse_cookie_lock.release, release=parse_cookie_lock.release,
): ):
...@@ -1069,22 +1073,29 @@ def parse_cookie(text, ...@@ -1069,22 +1073,29 @@ def parse_cookie(text,
acquire() acquire()
try: try:
if qparmre.match(text) >= 0:
mo_q = qparmre.match(text)
if mo_q:
# Match quoted correct cookies # Match quoted correct cookies
name=qparmre.group(2)
value=qparmre.group(3) l = len(mo_q.group(1))
l=len(qparmre.group(1)) name = mo_q.group(2)
elif parmre.match(text) >= 0: value = mo_q.group(3)
# Match evil MSIE cookies ;)
name=parmre.group(2)
value=parmre.group(3)
l=len(parmre.group(1))
else: else:
# this may be an invalid cookie. # Match evil MSIE cookies ;)
# We'll simply bail without raising an error
# if the cookie is invalid. mo_p = parmre.match(text)
return result
if mo_p:
l = len(mo_p.group(1))
name = mo_p.group(2)
value = mo_p.group(3)
else:
return result
finally: release() finally: release()
if not already_have(name): result[name]=value if not already_have(name): result[name]=value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment