diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-05-30 02:08:49 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-05-30 02:08:49 -0400 |
commit | f5060c9334cc0c96f11ee085b74d290c2b1d00db (patch) | |
tree | a93b2a7613c8153c8a3b18eb68d84648a976ae33 /Command/FromKey.hs | |
parent | 50301b7bda1854f571b87f3357ee00d6c625af56 (diff) |
fromkey, registerurl: Improve handling of urls that happen to also be parsable as strange keys.
Diffstat (limited to 'Command/FromKey.hs')
-rw-r--r-- | Command/FromKey.hs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Command/FromKey.hs b/Command/FromKey.hs index 584d913fc..51389b770 100644 --- a/Command/FromKey.hs +++ b/Command/FromKey.hs @@ -54,12 +54,20 @@ massAdd = go True =<< map (separate (== ' ')) . lines <$> liftIO getContents go status' rest go _ _ = error "Expected pairs of key and file on stdin, but got something else." +-- From user input to a Key. +-- User can input either a serialized key, or an url. +-- +-- In some cases, an input can be parsed as both a key and as an uri. +-- For example, "WORM--a:a" parses as an uri. To disambiguate, check +-- the uri scheme, to see if it looks like the prefix of a key. This relies +-- on key backend names never containing a ':'. mkKey :: String -> Key -mkKey s = case file2key s of - Just k -> k - Nothing -> case parseURI s of - Just _u -> Backend.URL.fromUrl s Nothing - Nothing -> error $ "bad key " ++ s +mkKey s = case parseURI s of + Just u | not (isKeyPrefix (uriScheme u)) -> + Backend.URL.fromUrl s Nothing + _ -> case file2key s of + Just k -> k + Nothing -> error $ "bad key/url " ++ s perform :: Key -> FilePath -> CommandPerform perform key file = do |