diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-05-25 18:10:31 -0700 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-05-25 18:10:31 -0700 |
commit | ee2950cd1979e7f5fdc6d5df43d83d0a6a0ce5dc (patch) | |
tree | f23ec4f984f9b15a8ce656113bf17c4cfa0f8d7b /libmproxy/utils.py | |
parent | a0c63b6108e76d24222b51def69c74fb88d72b0c (diff) | |
download | mitmproxy-ee2950cd1979e7f5fdc6d5df43d83d0a6a0ce5dc.tar.gz mitmproxy-ee2950cd1979e7f5fdc6d5df43d83d0a6a0ce5dc.tar.bz2 mitmproxy-ee2950cd1979e7f5fdc6d5df43d83d0a6a0ce5dc.zip |
Fix a crashing bug when replacing text in a flow with unicode bodies.
Diffstat (limited to 'libmproxy/utils.py')
-rw-r--r-- | libmproxy/utils.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/libmproxy/utils.py b/libmproxy/utils.py index e9c90320..337d4378 100644 --- a/libmproxy/utils.py +++ b/libmproxy/utils.py @@ -12,7 +12,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import os, datetime, urlparse, string, urllib +import os, datetime, urlparse, string, urllib, re import time, functools, cgi import json @@ -309,3 +309,15 @@ def parse_size(s): return int(s) * mult except ValueError: raise ValueError("Invalid size specification: %s"%s) + + +def safe_subn(pattern, repl, target, *args, **kwargs): + """ + There are Unicode conversion problems with re.subn. We try to smooth + that over by casting the pattern and replacement to strings. We really + need a better solution that is aware of the actual content ecoding. + """ + return re.subn(str(pattern), str(repl), target, *args, **kwargs) + + + |