Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
dist
dist-newstyle
.ghc.environment.*
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Changes for 0.23

- Escape URI paths
[#404](https://github.com/phadej/github/pull/404)
- Add OwnerBot to OwnerType
[#399](https://github.com/phadej/github/pull/399)
- Make File.fileSha optional
Expand Down
15 changes: 9 additions & 6 deletions src/GitHub/Request.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import Control.Monad.Catch (MonadCatch (..), MonadThrow)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Except (ExceptT (..), runExceptT)
import Data.Aeson (eitherDecode)
import Data.List (find)
import Data.List (find, intercalate)
import Data.String (fromString)
import Data.Tagged (Tagged (..))
import Data.Version (showVersion)
Expand All @@ -79,7 +79,9 @@ import Network.HTTP.Client
import Network.HTTP.Link.Parser (parseLinkHeaderBS)
import Network.HTTP.Link.Types (Link (..), LinkParam (..), href, linkParams)
import Network.HTTP.Types (Method, RequestHeaders, Status (..))
import Network.URI (URI, parseURIReference, relativeTo)
import Network.URI
(URI, escapeURIString, isUnescapedInURIComponent, parseURIReference,
relativeTo)

import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
Expand Down Expand Up @@ -409,11 +411,12 @@ makeHttpRequest auth r = case r of
. setMethod (toMethod m)
$ req
where
parseUrl' :: MonadThrow m => Text -> m HTTP.Request
parseUrl' = HTTP.parseUrlThrow . T.unpack
parseUrl' :: MonadThrow m => String -> m HTTP.Request
parseUrl' = HTTP.parseUrlThrow

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

setReqHeaders :: HTTP.Request -> HTTP.Request
setReqHeaders req = req { requestHeaders = reqHeaders <> requestHeaders req }
Expand Down