metadata: Field names limited to alphanumerics and a few whitelisted punctuation characters to avoid issues with views, etc.
This commit is contained in:
parent
ee8a443d49
commit
b437787eee
3 changed files with 20 additions and 8 deletions
|
@ -115,19 +115,29 @@ instance MetaSerializable CurrentlySet where
|
||||||
deserialize "-" = Just (CurrentlySet False)
|
deserialize "-" = Just (CurrentlySet False)
|
||||||
deserialize _ = Nothing
|
deserialize _ = Nothing
|
||||||
|
|
||||||
{- Fields cannot be empty, contain whitespace, or start with "+-" as
|
|
||||||
- that would break the serialization. -}
|
|
||||||
toMetaField :: String -> Maybe MetaField
|
toMetaField :: String -> Maybe MetaField
|
||||||
toMetaField f
|
toMetaField f
|
||||||
| legalField f = Just $ MetaField f
|
| legalField f = Just $ MetaField f
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
|
||||||
|
{- Fields cannot be empty, contain whitespace, or start with "+-" as
|
||||||
|
- that would break the serialization.
|
||||||
|
-
|
||||||
|
- Additionally, fields should not contain any form of path separator, as
|
||||||
|
- that would break views.
|
||||||
|
-
|
||||||
|
- So, require they have an alphanumeric first letter, with the remainder
|
||||||
|
- being either alphanumeric or a small set of shitelisted common punctuation.
|
||||||
|
-}
|
||||||
legalField :: String -> Bool
|
legalField :: String -> Bool
|
||||||
legalField f
|
legalField [] = False
|
||||||
| null f = False
|
legalField (c1:cs)
|
||||||
| any isSpace f = False
|
| not (isAlphaNum c1) = False
|
||||||
| any (`isPrefixOf` f) ["+", "-"] = False
|
| otherwise = all legalchars cs
|
||||||
| otherwise = True
|
where
|
||||||
|
legalchars c
|
||||||
|
| isAlphaNum c = True
|
||||||
|
| otherwise = c `elem` "_-."
|
||||||
|
|
||||||
toMetaValue :: String -> MetaValue
|
toMetaValue :: String -> MetaValue
|
||||||
toMetaValue = MetaValue (CurrentlySet True)
|
toMetaValue = MetaValue (CurrentlySet True)
|
||||||
|
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -11,6 +11,8 @@ git-annex (5.20140222) UNRELEASED; urgency=medium
|
||||||
tag/showname.
|
tag/showname.
|
||||||
* annex.genmetadata can be set to make git-annex automatically set
|
* annex.genmetadata can be set to make git-annex automatically set
|
||||||
metadata (year and month) when adding files.
|
metadata (year and month) when adding files.
|
||||||
|
* metadata: Field names limited to alphanumerics and a few whitelisted
|
||||||
|
punctuation characters to avoid issues with views, etc.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Fri, 21 Feb 2014 13:03:04 -0400
|
-- Joey Hess <joeyh@debian.org> Fri, 21 Feb 2014 13:03:04 -0400
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ fields, which each can have any number of values. For example, to tag
|
||||||
files, the `tag` field is typically used, with values set to each tag that
|
files, the `tag` field is typically used, with values set to each tag that
|
||||||
applies to the file.
|
applies to the file.
|
||||||
|
|
||||||
The field names are freeform (but cannot include spaces). The metadata
|
The field names are limited to alphanumerics (and `[_-.]`). The metadata
|
||||||
values can contain absolutely anything you like -- but you're recommended
|
values can contain absolutely anything you like -- but you're recommended
|
||||||
to keep it simple and reasonably short.
|
to keep it simple and reasonably short.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue