Repository navigation
Fall back to decimal for out of range roman numerals - #282
Merged
Merged
Conversation
eXpl0it3r
force-pushed
the
fix/negative-roman-counter
branch
from
November 10, 2026 19:06
7dd430f to
f334850
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A negative counter value in
lower-romanorupper-romanthrows anIndexOutOfRangeExceptionand the whole document fails to load, e.g.<ol start=-3 style="list-style-type: lower-roman"><li>a</ol>orcounter(c, upper-roman)with a negative counter.ConvertToRomanNumberslooks 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 likem(v). The roman styles only have the range 1 to 3999 in CSS Counter Styles 3, anything outside of it uses the fallback styledecimal, so -3 renders as "-3", 0 as "0" and 4000 as "4000".ConvertToRomanNumbersnow returns an empty string outside of 1 to 3999, whichcounter()already turns intodecimal. The list marker didn't have that fallback and rendered just "." for an empty conversion, it now usesdecimalas 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_FallsBackToDecimalandOlStart_OutsideTheStyleRange_FallsBackToDecimalcover negative, zero and too large values for the roman styles in bothcounter()and list markers, and fail on master.