-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use file-uri for better URI handling, fixes #978
- Loading branch information
Showing
7 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
{-| | ||
Module : GHCup.Utils.URI | ||
Description : GHCup domain specific URI utilities | ||
Copyright : (c) Julian Ospald, 2024 | ||
License : LGPL-3.0 | ||
Maintainer : hasufell@hasufell.de | ||
Stability : experimental | ||
Portability : portable | ||
This module contains GHCup helpers specific to | ||
URI handling. | ||
-} | ||
module GHCup.Utils.URI where | ||
|
||
import Data.ByteString | ||
import URI.ByteString hiding (parseURI) | ||
import System.URI.File | ||
|
||
import qualified URI.ByteString as URI | ||
|
||
|
||
----------- | ||
--[ URI ]-- | ||
----------- | ||
|
||
|
||
parseURI :: ByteString -> Either URIParseError (URIRef Absolute) | ||
parseURI bs = case parseFile bs of | ||
Left _ -> case URI.parseURI strictURIParserOptions bs of | ||
Right (URI { uriScheme = (Scheme "file") }) -> | ||
#if defined(IS_WINDOWS) | ||
Left (OtherError "Invalid file URI. File URIs must be absolute (start with a drive letter or UNC path) and not contain backslashes.") | ||
#else | ||
Left (OtherError "Invalid file URI. File URIs must be absolute.") | ||
#endif | ||
o -> o | ||
Right (FileURI (Just _) _) -> Left $ OtherError "File URIs with auth part are not supported!" | ||
Right (FileURI _ fp) -> Right $ URI (Scheme "file") Nothing fp (Query []) Nothing | ||
where | ||
parseFile | ||
#if defined(IS_WINDOWS) | ||
= parseFileURI ExtendedWindows | ||
#else | ||
= parseFileURI ExtendedPosix | ||
#endif | ||
|