Skip to content

Fall back to decimal for out of range roman numerals - #282

Merged
eXpl0it3r merged 1 commit into
masterfrom
fix/negative-roman-counter
Nov 10, 2026
Merged

eXpl0it3r merged 1 commit into
masterfrom
fix/negative-roman-counter

Conversation

@eXpl0it3r

Copy link
Copy Markdown
Collaborator

A negative counter value in lower-roman or upper-roman throws an IndexOutOfRangeException and the whole document fails to load, e.g. <ol start=-3 style="list-style-type: lower-roman"><li>a</ol> or counter(c, upper-roman) with a negative counter. ConvertToRomanNumbers looks up every digit in a table without any range check, so a negative digit (or a 10 for values of 10000 and above) indexes outside of it, and values from 4000 to 9999 turned into things like m(v). The roman styles only have the range 1 to 3999 in CSS Counter Styles 3, anything outside of it uses the fallback style decimal, so -3 renders as "-3", 0 as "0" and 4000 as "4000".

ConvertToRomanNumbers now returns an empty string outside of 1 to 3999, which counter() already turns into decimal. The list marker didn't have that fallback and rendered just "." for an empty conversion, it now uses decimal as well. The other styles in the same helper (alpha, latin, greek, armenian, georgian, hebrew, hiragana, katakana) don't crash on 0 or negative values, they already return an empty string, but because of the missing fallback in the list marker, <ol start=0 style="list-style-type: lower-alpha"> showed "." instead of "0.". That's fixed by the same change.

How to test this PR?

CI should succeed. ConvertToAlphaNumber_RomanOutOfRange_ReturnsEmpty, FormatCounterValue_AlphabeticStyleOutOfRange_FallsBackToDecimal and OlStart_OutsideTheStyleRange_FallsBackToDecimal cover negative, zero and too large values for the roman styles in both counter() and list markers, and fail on master.

@eXpl0it3r
eXpl0it3r force-pushed the fix/negative-roman-counter branch from 7dd430f to f334850 Compare November 10, 2026 19:06
@eXpl0it3r
eXpl0it3r merged commit 95ec82b into master Nov 10, 2026
26 of 27 checks passed
@eXpl0it3r
eXpl0it3r deleted the fix/negative-roman-counter branch November 10, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant