git.iko.soy/typeable/pandoc
on master help sign in
Fall back to latin1 if UTF-8 decoding fails...
d30791aJohn MacFarlane
src/Text/Pandoc/App.hs+7−1
@@ -1,3 +1,4 @@
1+{-# LANGUAGE LambdaCase #-}
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE CPP #-}
3{-# LANGUAGE CPP #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE ScopedTypeVariables #-}
@@ -352,7 +353,12 @@ readURI src = do
352 Just "UTF-8" -> return $ UTF8.toText bs
353 Just "UTF-8" -> return $ UTF8.toText bs
353 Just "ISO-8859-1" -> return $ T.pack $ B8.unpack bs
354 Just "ISO-8859-1" -> return $ T.pack $ B8.unpack bs
354 Just charset -> throwError $ PandocUnsupportedCharsetError charset
355 Just charset -> throwError $ PandocUnsupportedCharsetError charset
356+ Nothing -> liftIO $ -- try first as UTF-8, then as latin1
355− Nothing -> return $ UTF8.toText bs
357+ E.catch (return $! UTF8.toText bs)
358+ (\case
359+ TSE.DecodeError{} ->
360+ return $ T.pack $ B8.unpack bs
361+ e -> E.throwIO e)
356
362
357readFile' :: MonadIO m => FilePath -> m BL.ByteString
363readFile' :: MonadIO m => FilePath -> m BL.ByteString
358readFile' "-" = liftIO BL.getContents
364readFile' "-" = liftIO BL.getContents