aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/utils.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-05-25 18:10:31 -0700
committerAldo Cortesi <aldo@nullcube.com>2012-05-25 18:10:31 -0700
commitee2950cd1979e7f5fdc6d5df43d83d0a6a0ce5dc (patch)
treef23ec4f984f9b15a8ce656113bf17c4cfa0f8d7b /libmproxy/utils.py
parenta0c63b6108e76d24222b51def69c74fb88d72b0c (diff)
downloadmitmproxy-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.py14
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)
+
+
+