Skip to content

Commit 4d33389

Browse files
authored
fix(core): Error on excess unparsable input on measurements and lengths (#2260)
1 parent 9038e4a commit 4d33389

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

types/length.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ function length:_init (spec, stretch, shrink)
4949
if type(amount) == "number" then
5050
self:_init(amount)
5151
else
52-
local parsed = SILE.parserBits.length:match(spec)
52+
local input = pl.stringx.strip(spec)
53+
local length_only_parser = SILE.parserBits.length * -1
54+
local parsed = length_only_parser:match(input)
5355
if not parsed then
5456
SU.error("Could not parse length '" .. spec .. "'")
5557
end

types/measurement.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ function measurement:_init (amount, unit)
7878
elseif type(tonumber(amount)) == "number" then
7979
self.amount = tonumber(amount)
8080
elseif type(amount) == "string" then
81-
local parsed = SILE.parserBits.measurement:match(amount)
81+
local input = pl.stringx.strip(amount)
82+
local measurement_only_parser = SILE.parserBits.measurement * -1
83+
local parsed = measurement_only_parser:match(input)
8284
if not parsed then
8385
SU.error("Could not parse measurement '" .. amount .. "'")
8486
end

types/unit.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ setmetatable(unittypes, {
1515
local def = SU.required(spec, "definition", "registering unit " .. unit)
1616
local relative = SU.boolean(spec.relative, false)
1717
if type(def) == "string" then
18-
local parsed = bits.measurement:match(def)
18+
local input = pl.stringx.strip(def)
19+
local measurement_only_parser = bits.measurement * -1
20+
local parsed = measurement_only_parser:match(input)
1921
if not parsed then
2022
SU.error("Could not parse unit definition '" .. def .. "'")
2123
end

0 commit comments

Comments
 (0)