diff --git a/src/Hpack/Config.hs b/src/Hpack/Config.hs index 961cc9a4..7142ad7c 100644 --- a/src/Hpack/Config.hs +++ b/src/Hpack/Config.hs @@ -90,6 +90,7 @@ import Data.Map.Lazy (Map) import qualified Data.Map.Lazy as Map import qualified Data.HashMap.Lazy as HashMap import Data.List (nub, (\\), sortBy, intercalate) +import qualified Data.List.NonEmpty as NE import Data.Maybe import Data.Semigroup (Semigroup(..)) import Data.Ord @@ -588,8 +589,8 @@ instance FromValue GitHub where fromValue v = do input <- fromValue v case map T.unpack $ T.splitOn "/" input of - [owner, repo, subdir] -> return $ GitHub owner repo (Just subdir) - [owner, repo] -> return $ GitHub owner repo Nothing + (owner: _) | owner `elem` ["http:", "https:"] -> fail $ "expected owner/repo or owner/repo/subdir, but encountered url instead: " ++ show input + (owner: repo: subdir) -> return $ GitHub owner repo $ intercalate "/" . NE.toList <$> NE.nonEmpty subdir _ -> fail $ "expected owner/repo or owner/repo/subdir, but encountered " ++ show input data DefaultsConfig = DefaultsConfig { diff --git a/test/EndToEndSpec.hs b/test/EndToEndSpec.hs index 9a3e88ca..e7bab91f 100644 --- a/test/EndToEndSpec.hs +++ b/test/EndToEndSpec.hs @@ -119,7 +119,7 @@ spec = around_ (inTempDirectoryNamed "foo") $ do location: https://github.com/sol/hpack |] - it "accepts owner/repo/path" $ do + it "accepts owner/repo" $ do [i| github: hspec/hspec/hspec-core |] `shouldRenderTo` package [i| @@ -131,10 +131,22 @@ spec = around_ (inTempDirectoryNamed "foo") $ do subdir: hspec-core |] + it "accepts owner/repo/path" $ do + [i| + github: hspec/hspec/hspec-core/a/b/c/d/e + |] `shouldRenderTo` package [i| + homepage: https://github.com/hspec/hspec#readme + bug-reports: https://github.com/hspec/hspec/issues + source-repository head + type: git + location: https://github.com/hspec/hspec + subdir: hspec-core/a/b/c/d/e + |] + it "rejects URLs" $ do [i| github: https://github.com/sol/hpack/issues/365 - |] `shouldFailWith` "package.yaml: Error while parsing $.github - expected owner/repo or owner/repo/subdir, but encountered \"https://github.com/sol/hpack/issues/365\"" + |] `shouldFailWith` "package.yaml: Error while parsing $.github - expected owner/repo or owner/repo/subdir, but encountered url instead: \"https://github.com/sol/hpack/issues/365\"" describe "homepage" $ do it "accepts homepage URL" $ do