Repository navigation
🐛 FIX: section_ref no longer raises on very long digit runs - #168
Merged
Merged
Conversation
`§` followed by more than 4300 digits made `int()` raise ValueError (Python's integer string conversion limit), aborting the whole render. A level longer than nine digits now makes the rule decline, so the text renders literally and no shorter prefix is captured. Nine digits keeps every number below 10**9 (a signed 32-bit int) and far below the conversion limit, which cannot be configured below 640.
Drop the many-refs timing case: it goes through the valid-reference path this change does not touch, and on PyPy it mostly measures markdown-it-py's renderer, whose string concatenation is quadratic there (it failed the 1s budget, and took about 3s with --cov). Raise the budget to 3s, which still catches a quadratic scan (tens of seconds at 200k characters), and drop the redundant timeout marker (pyproject.toml already sets timeout = 10). Say in the docstring that leading zeros count towards the nine digits.
The budget catches a scan that does Python-level work per character, or a backtracking regex. A quadratic scan built from string slices can still pass it, so the docstring no longer claims every quadratic scan would take tens of seconds.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #168 +/- ##
==========================================
+ Coverage 92.80% 94.66% +1.86%
==========================================
Files 31 40 +9
Lines 1835 2325 +490
==========================================
+ Hits 1703 2201 +498
+ Misses 132 124 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
The
section_refplugin added in #144 crashes the whole render on hostile input:a
§followed by more than 4300 digits makesint()raiseValueError,because Python limits integer string conversion to 4300 digits by default.
For example,
md.render("see §" + "1" * 5000)raises on master.This blocks tagging 0.7.0.
The rule now declines when any dotted level of the number has more than nine digits
(leading zeros count). The whole text then renders literally:
no shorter prefix is captured, so a number is never split.
For example,
§1.1234567890.2stays plain text.References whose levels have at most nine digits behave exactly as before.
Why nine digits:
so
sys.set_int_max_str_digitscannot bring the crash back;The regex is unchanged. It has no ambiguous quantifiers, so it scans in linear time.
Tests:
(a later
§3on the same line is still captured), and leading zeros counting towards the bound;§+ 5000 digits renders as text with no exception;meta["numbers"]at the bound, and four over-long shapes that decline to a single text token;(a per-character quadratic scan or a backtracking regex would take far longer).
Without the fix, ten of the new tests fail.
The full suite passes on CPython and PyPy, pre-commit passes,
and the docs build with
-nW.