Skip to content

fix(format): recognize quote and backtick wrapping in is_wrapped - #6813

Open
eeshsaxena wants to merge 2 commits into
reflex-dev:mainfrom
eeshsaxena:fix/is-wrapped-identical-delimiters
Open

fix(format): recognize quote and backtick wrapping in is_wrapped#6813
eeshsaxena wants to merge 2 commits into
reflex-dev:mainfrom
eeshsaxena:fix/is-wrapped-identical-delimiters

Conversation

@eeshsaxena

Copy link
Copy Markdown

is_wrapped() never recognizes quote- or backtick-wrapped text, so wrap() with the default check_first=True double-wraps it:

from reflex.utils.format import wrap
wrap("`x`", "`")   # "``x``"  (expected "`x`")
wrap('"x"', '"')    # '""x""' (expected '"x"')

When open == close (the quote and backtick entries in WRAP_MAP), the opening delimiter matched both if ch == open and if ch == close on the same character, so depth dropped straight back to 0 and the function returned False for 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_wrapped only exercised { and (, so the quote/backtick cases are added (including `a`b` which should stay False).

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 importing reflex_base.utils.format directly and running the parametrized cases plus the distinct-delimiter regressions, which all pass, and confirming wrap("x", "")` is now idempotent.

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.
@eeshsaxena
eeshsaxena requested a review from a team as a code owner July 26, 2026 15:25
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@greptile-apps

greptile-apps Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR updates identical-delimiter wrapping detection.

  • Recognizes simply quoted and backtick-wrapped text as already wrapped.
  • Rejects single or structurally repeated delimiters.
  • Adds unit cases and a bug-fix news entry.

Confidence Score: 4/5

The 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 is_wrapped() return false and causes wrap() to add a second delimiter pair.

Files Needing Attention: packages/reflex-base/src/reflex_base/utils/format.py

Important Files Changed

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

Comment thread packages/reflex-base/src/reflex_base/utils/format.py
@codspeed-hq

codspeed-hq Bot commented Jul 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing eeshsaxena:fix/is-wrapped-identical-delimiters (804d7c6) with main (416eb34)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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]

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant