aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2014-01-08 12:04:08 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2014-01-08 12:04:08 -0800
commitaada7b495bf4af9912603b3b7649dd0d63f9b5fc (patch)
treefe7ca427dd60941172c915671155cb83d728e86a
parent8ef758fa68f67ddeff041ee2b9a404983ff2723c (diff)
downloadpandoc-aada7b495bf4af9912603b3b7649dd0d63f9b5fc.tar.gz
fetchItem: Handle image URLs beginning with '//'.
-rw-r--r--src/Text/Pandoc/Shared.hs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 3446f4343..714402e42 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -91,7 +91,8 @@ import Data.Char ( toLower, isLower, isUpper, isAlpha,
isLetter, isDigit, isSpace )
import Data.List ( find, isPrefixOf, intercalate )
import qualified Data.Map as M
-import Network.URI ( escapeURIString, isURI, unEscapeString )
+import Network.URI ( escapeURIString, isURI, nonStrictRelativeTo,
+ unEscapeString, parseURIReference )
import System.Directory
import Text.Pandoc.MIME (getMimeType)
import System.FilePath ( (</>), takeExtension, dropExtension )
@@ -623,9 +624,13 @@ fetchItem :: Maybe String -> String
-> IO (Either E.SomeException (BS.ByteString, Maybe String))
fetchItem sourceURL s
| isURI s = openURL s
- | otherwise = case sourceURL of
- Just u -> openURL (u ++ "/" ++ s)
- Nothing -> E.try readLocalFile
+ | otherwise =
+ case sourceURL >>= parseURIReference of
+ Just u -> case parseURIReference s of
+ Just s' -> openURL $ show $
+ s' `nonStrictRelativeTo` u
+ Nothing -> openURL $ show u ++ "/" ++ s
+ Nothing -> E.try readLocalFile
where readLocalFile = do
let mime = case takeExtension s of
".gz" -> getMimeType $ dropExtension s