From 18d11103f5ea8d054cb65a5226d09a991c783aa0 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Sun, 29 Sep 2019 13:01:00 -0700
Subject: [PATCH] RST reader: don't strip final underscore from absolute URI.

Partially addresses #5763.
---
 src/Text/Pandoc/Readers/RST.hs | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index ce7af9866..35b9ade65 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -1497,9 +1497,13 @@ explicitLink = try $ do
                    then B.str src
                    else label'
   -- `link <google_>` is a reference link to _google!
-  ((src',tit),attr) <- case reverse src of
-                          '_':xs -> lookupKey [] (toKey (reverse xs))
-                          _      -> return ((src, ""), nullAttr)
+  ((src',tit),attr) <-
+    if isURI src
+       then return ((src, ""), nullAttr)
+       else
+         case reverse src of
+            '_':xs -> lookupKey [] (toKey (reverse xs))
+            _      -> return ((src, ""), nullAttr)
   return $ B.linkWith attr (escapeURI src') tit label''
 
 citationName :: PandocMonad m => RSTParser m String