git.iko.soy/typeable/pandoc
on master help sign in
Percent-encode more special characters in URLs.

HTML, LaTeX writers adjusted. The special characters are '<','>','|','"','{','}','[',']','^', '`'. Closes #1640, #2377.

commit1e8a25ad69db8fa372ac4ddbb5ac05ffb00ed052 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 11 Oct 2015, 17:06 (11 years ago) parent04307a1
3 files changed+14−9
src/Text/Pandoc/Shared.hs+5−2 src/Text/Pandoc/Writers/LaTeX.hs+5−5 tests/Tests/Readers/Markdown.hs+4−2
src/Text/Pandoc/Shared.hs+5−2
@@ -288,9 +288,12 @@ toRomanNumeral x =
288288 _ | x >= 1 -> "I" ++ toRomanNumeral (x - 1)
289289 _ -> ""
290290
291−-- | Escape whitespace in URI.
291+-- | Escape whitespace and some punctuation characters in URI.
292292escapeURI :: String -> String
293−escapeURI = escapeURIString (not . isSpace)
293+escapeURI = escapeURIString (not . needsEscaping)
294+ where needsEscaping c = isSpace c || c `elem`
295+ ['<','>','|','"','{','}','[',']','^', '`']
296+
294297
295298-- | Convert tabs to spaces and filter out DOS line endings.
296299-- Tabs will be preserved if tab stop is set to 0.
src/Text/Pandoc/Writers/LaTeX.hs+5−5
@@ -242,7 +242,7 @@ stringToLaTeX ctx (x:xs) = do
242242 '^' -> "\\^{}" ++ rest
243243 '\\'| isUrl -> '/' : rest -- NB. / works as path sep even on Windows
244244 | otherwise -> "\\textbackslash{}" ++ rest
245− '|' -> "\\textbar{}" ++ rest
245+ '|' | not isUrl -> "\\textbar{}" ++ rest
246246 '<' -> "\\textless{}" ++ rest
247247 '>' -> "\\textgreater{}" ++ rest
248248 '[' -> "{[}" ++ rest -- to avoid interpretation as
@@ -848,17 +848,17 @@ inlineToLaTeX (Link txt (src, _)) =
848848 case txt of
849849 [Str x] | escapeURI x == src -> -- autolink
850850 do modify $ \s -> s{ stUrl = True }
851− src' <- stringToLaTeX URLString src
851+ src' <- stringToLaTeX URLString (escapeURI src)
852852 return $ text $ "\\url{" ++ src' ++ "}"
853853 [Str x] | Just rest <- stripPrefix "mailto:" src,
854854 escapeURI x == rest -> -- email autolink
855855 do modify $ \s -> s{ stUrl = True }
856− src' <- stringToLaTeX URLString src
856+ src' <- stringToLaTeX URLString (escapeURI src)
857857 contents <- inlineListToLaTeX txt
858858 return $ "\\href" <> braces (text src') <>
859859 braces ("\\nolinkurl" <> braces contents)
860860 _ -> do contents <- inlineListToLaTeX txt
861− src' <- stringToLaTeX URLString src
861+ src' <- stringToLaTeX URLString (escapeURI src)
862862 return $ text ("\\href{" ++ src' ++ "}{") <>
863863 contents <> char '}'
864864inlineToLaTeX (Image _ (source, _)) = do
@@ -866,7 +866,7 @@ inlineToLaTeX (Image _ (source, _)) = do
866866 let source' = if isURI source
867867 then source
868868 else unEscapeString source
869− source'' <- stringToLaTeX URLString source'
869+ source'' <- stringToLaTeX URLString (escapeURI source')
870870 inHeading <- gets stInHeading
871871 return $
872872 (if inHeading then "\\protect\\includegraphics" else "\\includegraphics")
tests/Tests/Readers/Markdown.hs+4−2
@@ -66,9 +66,11 @@ bareLinkTests =
6666 , ("http://en.wikipedia.org/wiki/Sprite_(computer_graphics)",
6767 autolink "http://en.wikipedia.org/wiki/Sprite_(computer_graphics)")
6868 , ("http://en.wikipedia.org/wiki/Sprite_[computer_graphics]",
69− autolink "http://en.wikipedia.org/wiki/Sprite_[computer_graphics]")
69+ link "http://en.wikipedia.org/wiki/Sprite_%5Bcomputer_graphics%5D" ""
70+ (str "http://en.wikipedia.org/wiki/Sprite_[computer_graphics]"))
7071 , ("http://en.wikipedia.org/wiki/Sprite_{computer_graphics}",
71− autolink "http://en.wikipedia.org/wiki/Sprite_{computer_graphics}")
72+ link "http://en.wikipedia.org/wiki/Sprite_%7Bcomputer_graphics%7D" ""
73+ (str "http://en.wikipedia.org/wiki/Sprite_{computer_graphics}"))
7274 , ("http://example.com/Notification_Center-GitHub-20101108-140050.jpg",
7375 autolink "http://example.com/Notification_Center-GitHub-20101108-140050.jpg")
7476 , ("https://github.com/github/hubot/blob/master/scripts/cream.js#L20-20",