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 2 commits 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 SummaryThe PR updates identical-delimiter wrapping detection.
Confidence Score: 4/5The PR does not appear safe to merge until escaped quote and backtick delimiters are recognized without double-wrapping valid content. The new identical-delimiter branch performs a raw substring check, so an escaped interior delimiter still makes Files Needing Attention: packages/reflex-base/src/reflex_base/utils/format.py
|
| Filename | Overview |
|---|---|
| packages/reflex-base/src/reflex_base/utils/format.py | Adds a dedicated identical-delimiter check, but the previously reported escaped-delimiter behavior remains unresolved. |
| tests/units/utils/test_format.py | Adds coverage for simple quote/backtick wrapping, an interior delimiter, and a lone delimiter. |
| news/6813.bugfix.md | Documents the intended correction to quote and backtick wrapping detection. |
Reviews (2): Last reviewed commit: "chore(changelog): add news fragment for ..." | Re-trigger Greptile
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/reflex-base/src/reflex_base/utils/format.py">
<violation number="1" location="packages/reflex-base/src/reflex_base/utils/format.py:104">
P2: Already-wrapped strings containing escaped quotes/backticks are still double-wrapped because this rejects every interior delimiter, including escaped ones. Consider rejecting only unescaped interior delimiters (and ensuring the final delimiter itself is unescaped).</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
| # 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.
P2: Already-wrapped strings containing escaped quotes/backticks are still double-wrapped because this rejects every interior delimiter, including escaped ones. Consider rejecting only unescaped interior delimiters (and ensuring the final delimiter itself is unescaped).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/reflex-base/src/reflex_base/utils/format.py, line 104:
<comment>Already-wrapped strings containing escaped quotes/backticks are still double-wrapped because this rejects every interior delimiter, including escaped ones. Consider rejecting only unescaped interior delimiters (and ensuring the final delimiter itself is unescaped).</comment>
<file context>
@@ -95,9 +95,14 @@ def is_wrapped(text: str, open: str, close: str | None = None) -> bool:
+ # 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]
+
depth = 0
</file context>
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.