Make the journal line limit configurable
This commit is contained in:
4 files changed
+15
-2
No files matched your search
@@ -3,6 +3,7 @@ en:
|
||||
hledger_enabled: "Enable the hledger plugin"
|
||||
hledger_path: "Path to the hledger executable"
|
||||
hledger_max_journal_bytes: "Maximum size of an hledger journal in bytes"
|
||||
hledger_max_journal_lines: "Maximum number of lines in an hledger journal"
|
||||
hledger_timeout_seconds: "Maximum number of seconds an hledger command may run"
|
||||
hledger_max_output_bytes: "Maximum number of bytes captured from hledger output"
|
||||
hledger_memory_limit_mb: "Maximum memory in megabytes the hledger process may use; set to 0 to disable the limit"
|
||||
|
||||
@@ -6,6 +6,9 @@ hledger:
|
||||
default: hledger
|
||||
hledger_max_journal_bytes:
|
||||
default: 262144
|
||||
hledger_max_journal_lines:
|
||||
default: 5000
|
||||
min: 1
|
||||
hledger_timeout_seconds:
|
||||
default: 10
|
||||
hledger_max_output_bytes:
|
||||
|
||||
@@ -7,7 +7,6 @@ module Hledger
|
||||
class Journal
|
||||
FENCE = /^[ \t]*`{3,}hledger[ \t]*\r?\n(?<source>.*?)^[ \t]*`{3,}[ \t]*$/m
|
||||
INCLUDE = /^[ \t]*!?[ \t]*include\b/i
|
||||
MAX_LINES = 5_000
|
||||
|
||||
Result =
|
||||
Struct.new(:source, :error, keyword_init: true) do
|
||||
@@ -46,7 +45,7 @@ module Hledger
|
||||
|
||||
def validate(source)
|
||||
return :too_large if source.bytesize > SiteSetting.hledger_max_journal_bytes
|
||||
return :too_many_lines if source.lines.size > MAX_LINES
|
||||
return :too_many_lines if source.lines.size > SiteSetting.hledger_max_journal_lines
|
||||
return :invalid_encoding unless source.valid_encoding?
|
||||
return :include_not_allowed if source.match?(INCLUDE)
|
||||
|
||||
|
||||
@@ -75,6 +75,16 @@ RSpec.describe Hledger::Journal do
|
||||
SiteSetting.hledger_max_journal_bytes = 262_144
|
||||
end
|
||||
|
||||
it "rejects journals with too many lines" do
|
||||
SiteSetting.hledger_max_journal_lines = 2
|
||||
|
||||
result = described_class.extract(raw_with("a\nb\nc"))
|
||||
|
||||
expect(result.error).to eq(:too_many_lines)
|
||||
ensure
|
||||
SiteSetting.hledger_max_journal_lines = 5000
|
||||
end
|
||||
|
||||
it "extracts a fence with trailing whitespace and a longer fence" do
|
||||
raw = "Intro\n\n````hledger \n2024-01-01 x\n a 1\n b -1\n````\n\nOutro\n"
|
||||
|
||||
|
||||
Reference in new issue
Block a user