posix: fix HFS+ percent-encoding folding stable
authorMatt Mackall <mpm@selenic.com>
Wed, 23 Nov 2011 14:22:37 -0800
branchstable
changeset 15563 b61fa7481a68
parent 15554 0c0ed2b3082d
child 15564 e45dadde2761
posix: fix HFS+ percent-encoding folding We use 'ignore' rather than 'replace' so we don't have to deal with u+FFFD in UTF-8 round-trip.
mercurial/posix.py
--- a/mercurial/posix.py	Tue Nov 22 19:56:26 2011 +0100
+++ b/mercurial/posix.py	Wed Nov 23 14:22:37 2011 -0800
@@ -176,13 +176,15 @@
             u = path.decode('utf-8')
         except UnicodeDecodeError:
             # percent-encode any characters that don't round-trip
-            p2 = path.decode('utf-8', 'replace').encode('utf-8')
+            p2 = path.decode('utf-8', 'ignore').encode('utf-8')
             s = ""
-            for a, b in zip(path, p2):
-                if a != b:
-                    s += "%%%02X" % ord(a)
+            pos = 0
+            for c in path:
+                if p2[pos:pos + 1] == c:
+                    s += c
+                    pos += 1
                 else:
-                    s += a
+                    s += "%%%02X" % ord(c)
             u = s.decode('utf-8')
 
         # Decompose then lowercase (HFS+ technote specifies lower)