fix(format): recognize quote and backtick wrapping in is_wrapped - #6813
fix(format): recognize quote and backtick wrapping in is_wrapped#6813eeshsaxena wants to merge 1 commit into
Conversation
When open == close (the quote and backtick entries in WRAP_MAP) the opening
delimiter both opened and closed the depth counter on the same character, so
is_wrapped returned False for any such string. wrap(text, open) with the
default check_first=True therefore never detected already-wrapped input and
double-wrapped it, e.g. wrap('`x`', '`') -> '``x``'.
Identical delimiters cannot nest, so treat the text as wrapped when the
delimiter does not reappear inside the content. test_is_wrapped only covered
distinct delimiters; add the quote/backtick cases.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Greptile SummaryThis PR updates identical-delimiter wrapping detection and expands its unit coverage.
Confidence Score: 4/5The escaped-delimiter case should be fixed before merging because valid already wrapped strings can still be wrapped a second time. The new branch recognizes simple quote- and backtick-wrapped values, but its raw membership check treats escaped interior delimiters as structural and causes the default wrapping path to duplicate the outer delimiters. Files Needing Attention: packages/reflex-base/src/reflex_base/utils/format.py, tests/units/utils/test_format.py
|
| Filename | Overview |
|---|---|
| packages/reflex-base/src/reflex_base/utils/format.py | Adds identical-delimiter recognition, but the raw interior check misclassifies escaped delimiters and can still cause double wrapping. |
| tests/units/utils/test_format.py | Covers the newly supported basic cases but omits escaped quote and backtick content. |
Reviews (1): Last reviewed commit: "fix(format): recognize quote and backtic..." | Re-trigger Greptile
| # Identical delimiters (e.g. quotes or backticks) cannot nest, so the text | ||
| # is wrapped only when the delimiter does not reappear inside the content. | ||
| if open == close: | ||
| return open not in text[1:-1] |
There was a problem hiding this comment.
is_wrapped()never recognizes quote- or backtick-wrapped text, sowrap()with the defaultcheck_first=Truedouble-wraps it:When
open == close(the quote and backtick entries inWRAP_MAP), the opening delimiter matched bothif ch == openandif ch == closeon the same character, sodepthdropped straight back to 0 and the function returnedFalsefor any such string.wrap(text, open)then never noticed the input was already wrapped and wrapped it again.Identical delimiters can't nest, so this handles them directly: the text counts as wrapped when the delimiter doesn't reappear inside the content. Distinct-delimiter behavior is unchanged.
test_is_wrappedonly exercised{and(, so the quote/backtick cases are added (including`a`b`which should stayFalse).I couldn't run the full unit suite locally: its conftest imports
reflex_components_core, and pydantic v1 doesn't load on my Python 3.14. I verified instead by importingreflex_base.utils.formatdirectly and running the parametrized cases plus the distinct-delimiter regressions, which all pass, and confirmingwrap("x", "")` is now idempotent.