Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1eb7257

Browse files
authored
Merge pull request haskell-github#404 from phadej/escape-paths
Escape URI paths
2 parents ad2eb57 + a40db0d commit 1eb7257

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.env
12
dist
23
dist-newstyle
34
.ghc.environment.*

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Changes for 0.23
22

3+
- Escape URI paths
4+
[#404](https://github.com/phadej/github/pull/404)
35
- Add OwnerBot to OwnerType
46
[#399](https://github.com/phadej/github/pull/399)
57
- Make File.fileSha optional

src/GitHub/Request.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import Control.Monad.Catch (MonadCatch (..), MonadThrow)
6767
import Control.Monad.Trans.Class (lift)
6868
import Control.Monad.Trans.Except (ExceptT (..), runExceptT)
6969
import Data.Aeson (eitherDecode)
70-
import Data.List (find)
70+
import Data.List (find, intercalate)
7171
import Data.String (fromString)
7272
import Data.Tagged (Tagged (..))
7373
import Data.Version (showVersion)
@@ -79,7 +79,9 @@ import Network.HTTP.Client
7979
import Network.HTTP.Link.Parser (parseLinkHeaderBS)
8080
import Network.HTTP.Link.Types (Link (..), LinkParam (..), href, linkParams)
8181
import Network.HTTP.Types (Method, RequestHeaders, Status (..))
82-
import Network.URI (URI, parseURIReference, relativeTo)
82+
import Network.URI
83+
(URI, escapeURIString, isUnescapedInURIComponent, parseURIReference,
84+
relativeTo)
8385

8486
import qualified Data.ByteString as BS
8587
import qualified Data.ByteString.Lazy as LBS
@@ -409,11 +411,12 @@ makeHttpRequest auth r = case r of
409411
. setMethod (toMethod m)
410412
$ req
411413
where
412-
parseUrl' :: MonadThrow m => Text -> m HTTP.Request
413-
parseUrl' = HTTP.parseUrlThrow . T.unpack
414+
parseUrl' :: MonadThrow m => String -> m HTTP.Request
415+
parseUrl' = HTTP.parseUrlThrow
414416

415-
url :: Paths -> Text
416-
url paths = maybe "https://api.github.com" id (endpoint =<< auth) <> "/" <> T.intercalate "/" paths
417+
url :: Paths -> String
418+
url paths = maybe "https://api.github.com" T.unpack (endpoint =<< auth) ++ "/" ++ intercalate "/" paths' where
419+
paths' = map (escapeURIString isUnescapedInURIComponent . T.unpack) paths
417420

418421
setReqHeaders :: HTTP.Request -> HTTP.Request
419422
setReqHeaders req = req { requestHeaders = reqHeaders <> requestHeaders req }

0 commit comments

Comments
 (0)