Skip to content

Commit

Permalink
Fix rebase_relative_paths extension for non-ASCII URLs.
Browse files Browse the repository at this point in the history
We need to escae non-ASCII URLs before passing them to parseURI,
or it will choke.

Closes #148.
  • Loading branch information
jgm committed Feb 28, 2024
1 parent 16cb938 commit 103e10c
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ where
import Commonmark.Types
import Commonmark.Syntax
import Commonmark.Inlines
import Data.Char (isAscii)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Maybe (fromMaybe)
import Text.Parsec (getPosition)
import System.FilePath
import qualified System.FilePath.Windows as Windows
import qualified System.FilePath.Posix as Posix
import Network.URI (URI (uriScheme), parseURI)
import Network.URI (URI (uriScheme), parseURI, escapeURIString)
import qualified Data.Set as Set

rebaseRelativePathsSpec
Expand Down Expand Up @@ -128,7 +129,7 @@ schemes = Set.fromList
-- | Check if the string is a valid URL with a IANA or frequently used but
-- unofficial scheme (see @schemes@).
isURI :: T.Text -> Bool
isURI = maybe False hasKnownScheme . parseURI . T.unpack
isURI = maybe False hasKnownScheme . parseURI . escapeURIString isAscii . T.unpack
where
hasKnownScheme = (`Set.member` schemes) . T.toLower .
T.filter (/= ':') . T.pack . uriScheme

0 comments on commit 103e10c

Please sign in to comment.