Skip to content

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

Open
eeshsaxena wants to merge 1 commit 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 1 commit 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

This PR updates identical-delimiter wrapping detection and expands its unit coverage.

  • Adds a minimum-length guard and special handling for quote and backtick delimiters.
  • Adds tests for simple wrapped values, an interior unescaped backtick, and a lone delimiter.

Confidence Score: 4/5

The 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

Important Files Changed

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]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Escaped delimiters trigger double wrapping

When an already wrapped string contains an escaped instance of its delimiter, such as `a\`b`, this raw substring check treats the escaped backtick as structural and returns false, causing wrap() to add another delimiter pair to the valid expression.

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