Skip to content

Commit 098031a

Browse files
committed
Escape URI paths
Resolves haskell-github#398
1 parent ad2eb57 commit 098031a

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
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: 6 additions & 3 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
@@ -413,7 +415,8 @@ makeHttpRequest auth r = case r of
413415
parseUrl' = HTTP.parseUrlThrow . T.unpack
414416

415417
url :: Paths -> Text
416-
url paths = maybe "https://api.github.com" id (endpoint =<< auth) <> "/" <> T.intercalate "/" paths
418+
url paths = maybe "https://api.github.com" id (endpoint =<< auth) <> "/" <> T.pack (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)