File tree Expand file tree Collapse file tree 1 file changed +34
-5
lines changed Expand file tree Collapse file tree 1 file changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -102,10 +102,39 @@ def ducky_main(request):
102102
103103 return (response )
104104
105- def cleanup_text (buffer ):
106- return_buffer = buffer .replace ('+' , ' ' ).replace ('%0D%0A' , '\n ' ) + '\n '
107- #print(return_buffer)
108- return (return_buffer )
105+ _hexdig = '0123456789ABCDEFabcdef'
106+ _hextobyte = None
107+
108+ def cleanup_text (string ):
109+ """unquote('abc%20def') -> b'abc def'."""
110+ global _hextobyte
111+
112+ if not string :
113+ return b''
114+
115+ if isinstance (string , str ):
116+ string = string .encode ('utf-8' )
117+
118+ bits = string .split (b'%' )
119+ if len (bits ) == 1 :
120+ return string
121+
122+ res = [bits [0 ]]
123+ append = res .append
124+
125+ if _hextobyte is None :
126+ _hextobyte = {(a + b ).encode (): bytes ([int (a + b , 16 )])
127+ for a in _hexdig for b in _hexdig }
128+
129+ for item in bits [1 :]:
130+ try :
131+ append (_hextobyte [item [:2 ]])
132+ append (item [2 :])
133+ except KeyError :
134+ append (b'%' )
135+ append (item )
136+
137+ return b'' .join (res ).decode ().replace ('+' ,' ' )
109138
110139web_app = WSGIApp ()
111140
@@ -211,4 +240,4 @@ async def startWebService():
211240 wsgiServer .start ()
212241 while True :
213242 wsgiServer .update_poll ()
214- await asyncio .sleep (0 )
243+ await asyncio .sleep (0 )
You can’t perform that action at this time.
0 commit comments