Restore lexer depth on the unclosed-bracket error path#791
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #791 +/- ##
=====================================
Coverage 87.4% 87.4%
=====================================
Files 104 104
Lines 13982 13983 +1
=====================================
+ Hits 12223 12224 +1
Misses 1759 1759 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Please rewrite the description. LLM-generated writing is not acceptable, and frankly I have no idea what it even means. There is no such thing as a "native" parser. Let me know when the description is rewritten and I will take a look. |
|
Rewrote the description and title. You're right that "native parser" was meaningless; it's a debug_assert in the format-description lexer. The opening bracket increments depth and the unclosed-bracket error path didn't restore it, so a later context() assert trips on inputs like |
|
Yes, please add a regression test for the inputs. They can go in the |
A component header immediately followed by an unclosed nested bracket (`[a[`, `[hour[`) could panic in debug builds. The opening bracket increments `self.depth`, but the unclosed-bracket error path returned without restoring it. `consume_component` swallows that error and re-derives the unclosed-bracket error itself, continuing with `depth` one too high, so a later `debug_assert!(self.context().is_component())` in `consume_whitespace` trips. Release builds skip the assert and report the unclosed bracket as before. Decrement `self.depth` on that error path so depth and context match the entry state, like the other early returns in this function. Add regression cases to `nested_v2_error_unclosed`.
07659d6 to
4712e1e
Compare
|
Added regression cases for |
|
Looks good; thanks! |
Parsing a format description with an unclosed nested bracket (
[a[,[optional [,[hour[) panics in debug builds viadebug_assert!(self.context().is_component()), reached throughconsume_whitespace.The opening bracket increments
self.depth. On the branch where no closing bracket is found, the lexer returnsUnclosedOpeningBracketwithout restoringself.depth.consume_componentdiscards that error and re-derives the unclosed-bracket error itself, so the lexer keeps going withdepthone too high;context()then reports the wrong context and the assert fails.The fix decrements
self.depthbefore returning, matching the entry state like the other early returns in this function. Release builds skip the assert, so the observable symptom is a debug-build panic; the underlying issue is the leftover depth on this error path.