@@ -91,7 +91,8 @@ import Data.Char ( toLower, isLower, isUpper, isAlpha,
9191 isLetter, isDigit, isSpace )
9292import Data.List ( find, isPrefixOf, intercalate )
9393import qualified Data.Map as M
94−import Network.URI ( escapeURIString, isURI, unEscapeString )
94+import Network.URI ( escapeURIString, isURI, nonStrictRelativeTo,
95+ unEscapeString, parseURIReference )
9596import System.Directory
9697import Text.Pandoc.MIME (getMimeType)
9798import System.FilePath ( (</>), takeExtension, dropExtension )
@@ -623,9 +624,13 @@ fetchItem :: Maybe String -> String
623624 -> IO (Either E.SomeException (BS.ByteString, Maybe String))
624625fetchItem sourceURL s
625626 | isURI s = openURL s
626− | otherwise = case sourceURL of
627− Just u -> openURL (u ++ "/" ++ s)
628− Nothing -> E.try readLocalFile
627+ | otherwise =
628+ case sourceURL >>= parseURIReference of
629+ Just u -> case parseURIReference s of
630+ Just s' -> openURL $ show $
631+ s' `nonStrictRelativeTo` u
632+ Nothing -> openURL $ show u ++ "/" ++ s
633+ Nothing -> E.try readLocalFile
629634 where readLocalFile = do
630635 let mime = case takeExtension s of
631636 ".gz" -> getMimeType $ dropExtension s