View | Details | Raw Unified | Return to bug 147706
Collapse All | Expand All

(-)www/rssdler/files/patch-percentUnQuote (+16 lines)
Added Link Here
1
Index: rssdler.py
2
===================================================================
3
--- rssdler.py	(revision 169)
4
+++ rssdler.py	(working copy)
5
@@ -363,9 +363,9 @@ def percentUnQuote( sStr, p=percentunQuoteDict, re
6
       replaced in order of the sequence"""
7
     for search in p:
8
         if search in reserved: continue
9
-        sStr = sStr.replace( search, p[search] )
10
+        sStr = re.sub('(?i)' + re.escape(search), p[search], sStr)
11
     for search in reserved:
12
-        sStr = sStr.replace( search, p[search])
13
+        sStr = re.sub('(?i)' + re.escape(search), p[search], sStr)
14
     return sStr
15
 
16
 def percentQuote(sStr, urlPart=(2,), pd=percentQuoteDict):
(-)www/rssdler/files/patch-xmlUnEscape (+32 lines)
Added Link Here
1
Index: rssdler.py
2
===================================================================
3
--- rssdler.py	(revision 169)
4
+++ rssdler.py	(working copy)
5
@@ -79,6 +79,7 @@ percentQuoteDict = {u'!': u'%21', u' ': u'%20', u'
6
   u';': u'%3B', u':': u'%3A', u']': u'%5D', u'[': u'%5B', u'?': u'%3F', 
7
   u'!':u'%7E'}
8
 percentunQuoteDict = dict(((j,i) for (i,j) in percentQuoteDict.items()))
9
+xmlUnEscapeDict = { u'&lt;' : u'<', u'&gt;' : u'>', u'&amp;' : u'&' }
10
 netscapeHeader= """# HTTP Cookie File
11
 # http://www.netscape.com/newsref/std/cookie_spec.html
12
 # This is a generated file!  Do not edit.\n\n"""
13
@@ -327,16 +328,15 @@ def unicodeC( s ):
14
         raise UnicodeEncodeError(u'could not encode %s to unicode' % s)
15
     return s
16
     
17
-def xmlUnEscape( sStr, percent=0, pd=percentunQuoteDict ):
18
+def xmlUnEscape( sStr, percent=0, pd=percentunQuoteDict, xd=xmlUnEscapeDict ):
19
     u"""xml unescape a string, by default also checking for percent encoded 
20
     characters. set percent=0 to ignore percent encoding. 
21
     can specify your own percent quote dict 
22
     (key, value) pairs are of (search, replace) ordering with percentunQuoteDict
23
     """
24
-    sStr = sStr.replace("&lt;", "<")
25
-    sStr = sStr.replace("&gt;", ">")
26
     if percent: sStr = percentUnQuote( sStr, pd )
27
-    sStr = sStr.replace("&amp;", "&")
28
+    for search in xd:
29
+        sStr = re.sub('(?i)' + re.escape(search), xd[search], sStr)
30
     return sStr
31
 
32
 def percentIsQuoted(sStr, testCases=percentQuoteDict.values()):

Return to bug 147706