summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-01-08 13:55:35 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-01-08 13:55:35 -0400
commit8df4e37f0dda20be0a13487f71bacf483aedaf58 (patch)
treefc628244c59aaa1e04658847c0a3ee8d4fbc45bd
parent6b4fc5e985ed96e14ebc89e67b373dd66c857bc5 (diff)
better fix for slash in view metadata
The homomorphs are back, just encoded such that it doesn't crash in LANG=C However, I noticed a bug in the old escaping; [pseudoSlash] was escaped the same as ['/','/']. Fixed by using '%' to escape pseudoSlash. Which requires doubling '%' to escape it, but that's already done in the escaping of worktree filenames in a view, so is probably ok.
-rw-r--r--Annex/View.hs36
-rw-r--r--debian/changelog5
-rw-r--r--doc/bugs/slash_in_metadata_breaks_field__61____42___view/comment_1_249d786ce15ab0c91191987c0bab76ef._comment3
3 files changed, 30 insertions, 14 deletions
diff --git a/Annex/View.hs b/Annex/View.hs
index 92a7ffc48..060301fd5 100644
--- a/Annex/View.hs
+++ b/Annex/View.hs
@@ -222,23 +222,37 @@ viewComponentMatcher viewcomponent = \metadata ->
| S.null s = Nothing
| otherwise = Just (S.toList s)
+-- This is '∕', a unicode character that displays the same as '/' but is
+-- not it. It is encoded using the filesystem encoding, which allows it
+-- to be used even when not in a unicode capable locale.
+pseudoSlash :: String
+pseudoSlash = "\56546\56456\56469"
+
+-- And this is '╲' similarly.
+pseudoBackslash :: String
+pseudoBackslash = "\56546\56469\56498"
+
toViewPath :: MetaValue -> FilePath
-toViewPath = concatMap escapeslash . fromMetaValue
+toViewPath = escapeslash [] . fromMetaValue
where
- escapeslash c
- | c == '/' = "%_"
- | c == '\\' = "%."
- | c == '%' = "%%"
- | otherwise = [c]
+ escapeslash s ('/':cs) = escapeslash (pseudoSlash:s) cs
+ escapeslash s ('\\':cs) = escapeslash (pseudoBackslash:s) cs
+ escapeslash s ('%':cs) = escapeslash ("%%":s) cs
+ escapeslash s (c1:c2:c3:cs)
+ | [c1,c2,c3] == pseudoSlash = escapeslash ("%":pseudoSlash:s) cs
+ | [c1,c2,c3] == pseudoBackslash = escapeslash ("%":pseudoBackslash:s) cs
+ | otherwise = escapeslash ([c1]:s) (c2:c3:cs)
+ escapeslash s cs = concat (reverse (cs:s))
fromViewPath :: FilePath -> MetaValue
fromViewPath = toMetaValue . deescapeslash []
where
- deescapeslash s [] = reverse s
- deescapeslash s ('%':'_':cs) = deescapeslash ('/':s) cs
- deescapeslash s ('%':'.':cs) = deescapeslash ('\\':s) cs
- deescapeslash s ('%':'%':cs) = deescapeslash ('%':s) cs
- deescapeslash s (c:cs) = deescapeslash (c:s) cs
+ deescapeslash s ('%':escapedc:cs) = deescapeslash ([escapedc]:s) cs
+ deescapeslash s (c1:c2:c3:cs)
+ | [c1,c2,c3] == pseudoSlash = deescapeslash ("/":s) cs
+ | [c1,c2,c3] == pseudoBackslash = deescapeslash ("\\":s) cs
+ | otherwise = deescapeslash ([c1]:s) (c2:c3:cs)
+ deescapeslash s cs = concat (reverse (cs:s))
prop_viewPath_roundtrips :: MetaValue -> Bool
prop_viewPath_roundtrips v = fromViewPath (toViewPath v) == v
diff --git a/debian/changelog b/debian/changelog
index 8c7258ccb..49af4347f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -48,9 +48,8 @@ git-annex (6.20151219) UNRELEASED; urgency=medium
* rekey: No longer copies over urls from the old to the new key.
It makes sense for migrate to do that, but not for this low-level
(and little used) plumbing command to.
- * view: Avoid using cute unicode homomorphs for '/' and '\' and instead
- use ugly escaping, as the unicode method doesn't work on non-unicode
- supporting systems.
+ * view: Fix crash in non-unicode capable locale when entering a view
+ of metadata containing a slash or backslash.
-- Joey Hess <id@joeyh.name> Sat, 19 Dec 2015 13:31:17 -0400
diff --git a/doc/bugs/slash_in_metadata_breaks_field__61____42___view/comment_1_249d786ce15ab0c91191987c0bab76ef._comment b/doc/bugs/slash_in_metadata_breaks_field__61____42___view/comment_1_249d786ce15ab0c91191987c0bab76ef._comment
index 2cd288951..f6fb82b51 100644
--- a/doc/bugs/slash_in_metadata_breaks_field__61____42___view/comment_1_249d786ce15ab0c91191987c0bab76ef._comment
+++ b/doc/bugs/slash_in_metadata_breaks_field__61____42___view/comment_1_249d786ce15ab0c91191987c0bab76ef._comment
@@ -21,4 +21,7 @@ unicode support.
Sigh, 2016 and still can't have nice things.. Suppose it'll have to use an
ugly encoding for them instead.
+
+Update: Can have nice things, just have to encode the characters using the
+FileSystemEncoding!
"""]]