Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#311] Fix a "resource exhausted" crash #312

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
Unreleased
==========

* [#311](https://github.com/serokell/xrefcheck/issues/311)
+ Fix a "resource exhausted" crash on repositories containing a large number
of Markdown files.

0.3.0
==========

Expand Down
10 changes: 4 additions & 6 deletions src/Xrefcheck/Scanners/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import CMarkGFM
import Control.Lens (_Just, makeLenses, makeLensesFor, use, (.=))
import Control.Monad.Trans.Writer.CPS (Writer, runWriter, tell)
import Data.Aeson (FromJSON (..), genericParseJSON)
import Data.ByteString.Lazy qualified as BSL
import Data.ByteString qualified as BS
import Data.DList qualified as DList
import Data.Reflection (Given)
import Data.Text qualified as T
import Data.Text.Lazy qualified as LT
import Fmt (Buildable (..), nameF)
import Text.HTML.TagSoup
import Text.Interpolation.Nyan
Expand Down Expand Up @@ -409,18 +408,17 @@ textToMode ("ignore" : [x])
| otherwise = InvalidMode x
textToMode _ = NotAnAnnotation

parseFileInfo :: MarkdownConfig -> String -> LT.Text -> (FileInfo, [ScanError 'Parse])
parseFileInfo :: MarkdownConfig -> String -> T.Text -> (FileInfo, [ScanError 'Parse])
parseFileInfo config pathForPrinting input
= runWriter
$ flip runReaderT (ExtractorCtx config pathForPrinting)
$ nodeExtractInfo
$ commonmarkToNode [optFootnotes] [extAutolink]
$ toStrict input
$ commonmarkToNode [optFootnotes] [extAutolink] input

markdownScanner :: Given PrintUnixPaths => MarkdownConfig -> ScanAction
markdownScanner config root relativePath =
parseFileInfo config pathForPrinting . decodeUtf8
<$> BSL.readFile rootedPath
<$> BS.readFile rootedPath
where
rootedPath = filePathFromRoot root relativePath
pathForPrinting = mkPathForPrinting rootedPath
Expand Down
Loading