fix: infinite loop when RULE_CALLABLE returns zero consumed characters#135
Open
gaoflow wants to merge 1 commit into
Open
fix: infinite loop when RULE_CALLABLE returns zero consumed characters#135gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
When a RULE_CALLABLE function returns (0, replacement_string), the _apply_rule_callable method never advances the string position, causing an infinite loop in unicode_to_latex()'s while loop. Add a guard that raises ValueError when consumed <= 0, with a helpful message pointing to the offending callable.
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
RULE_CALLABLEthat returns zero consumed characters causes aninfinite loop in
unicode_to_latex().Root cause:
_apply_rule_callable()passes the consumed countfrom the callable directly to
_apply_replacement()which doesp.pos += numchars. Whennumchars == 0, the position neveradvances, and the
while p.pos < len(s)loop re-fires the samerule on the same position endlessly.
Fix (+9 lines): Guard in
_apply_rule_callable()that raisesValueErrorifconsumed <= 0, with a descriptive message pointingto the offending callable and input position. Prevents the hang and
gives actionable feedback.
Reproduction:
286/286 tests pass.
This pull request was prepared with the assistance of AI, under my
direction and review.