diff options
| author | Albert Krewinkel <[email protected]> | 2024-01-29 17:39:10 +0100 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2024-01-29 17:41:44 +0100 |
| commit | d90444d4c869598434b3d4bee8386b16ff57b6f6 (patch) | |
| tree | 3bdff4845317a40b8077f308a89ed82201e896b8 /pandoc-lua-engine/src | |
| parent | ba6fc02b90301a39b808aac450e015c3291e665e (diff) | |
Lua: catch encoding error in `pandoc.read`
Fixed a bug that could lead to an un-catchable error and program
termination when `pandoc.read` was called with invalid UTF-8 input.
Fixes: #9385
Diffstat (limited to 'pandoc-lua-engine/src')
| -rw-r--r-- | pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs index 37d78bb83..cca4da6ec 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs @@ -20,11 +20,12 @@ module Text.Pandoc.Lua.Module.Pandoc import Prelude hiding (read) import Control.Applicative ((<|>)) import Control.Monad (forM_, when) -import Control.Monad.Catch (catch, throwM) +import Control.Monad.Catch (catch, handle, throwM) import Data.Data (Data, dataTypeConstrs, dataTypeOf, showConstr) import Data.Default (Default (..)) import Data.Maybe (fromMaybe) import Data.Proxy (Proxy (Proxy)) +import Data.Text.Encoding.Error (UnicodeException) import HsLua import System.Exit (ExitCode (..)) import Text.Pandoc.Definition @@ -210,7 +211,8 @@ functions = =?> "output string, or error triple" , defun "read" - ### (\content mformatspec mreaderOptions -> unPandocLua $ do + ### (\content mformatspec mreaderOptions -> + handle (failLua . show @UnicodeException) . unPandocLua $ do flvrd <- maybe (parseFlavoredFormat "markdown") pure mformatspec let readerOpts = fromMaybe def mreaderOptions getReader flvrd >>= \case |
