Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/6813.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed `is_wrapped` to recognize quote- and backtick-wrapped text so `wrap` no longer double-wraps it.
7 changes: 6 additions & 1 deletion packages/reflex-base/src/reflex_base/utils/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ def is_wrapped(text: str, open: str, close: str | None = None) -> bool:
Whether the text is wrapped.
"""
close = get_close_char(open, close)
if not (text.startswith(open) and text.endswith(close)):
if len(text) < 2 or not (text.startswith(open) and text.endswith(close)):
return False

# 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]
Comment thread
greptile-apps[bot] marked this conversation as resolved.

@cubic-dev-ai cubic-dev-ai Bot Jul 31, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Fix with cubic


depth = 0
for ch in text[:-1]:
if ch == open:
Expand Down
5 changes: 5 additions & 0 deletions tests/units/utils/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ def test_get_close_char(input: str, output: str):
("{wrap", "{", False),
("{wrap}", "(", False),
("(wrap)", "(", True),
# Identical delimiters (quotes/backticks) that cannot nest.
("`wrap`", "`", True),
('"wrap"', '"', True),
("`a`b`", "`", False),
("`", "`", False),
],
)
def test_is_wrapped(text: str, open: str, expected: bool):
Expand Down