reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Fix escaping quotes in dict values

Open picklelo opened this issue 3 years ago β€’ 1 comments

Currently escaping quotes in string props is not working always.

The following prop doesn't compile correctly:

pc.text(
    "hello",
    font_family='"Fira Code", Menlo, Consolas, monospace'
)

picklelo avatar Mar 09 '23 22:03 picklelo

Can I work on this?

wassafshahzad avatar Mar 10 '23 00:03 wassafshahzad

import reflex as rx


class State(rx.State):
    pass


def index() -> rx.Component:
    return rx.fragment(
        rx.vstack(
            rx.text(
                "broken",
                font_family='"Fira Code", Menlo, Consolas, monospace'
            ),
            rx.text(
                "working",
                font_family="'Fira Code', Menlo, Consolas, monospace"
            ),
            padding_top="10%",
        ),
    )


app = rx.App()
app.add_page(index)
app.compile()

reflex-0.2.4 generates code like

  <Text sx={{"fontFamily": ""Fira Code", Menlo, Consolas, monospace"}}>
  {`broken`}
</Text>
  <Text sx={{"fontFamily": "'Fira Code', Menlo, Consolas, monospace"}}>
  {`working`}
</Text>

The quotes around "Fira Code" are themselves wrapped in double quotes, and not escaped, which is obviously wrong.

With #1609 merging in for reflex-0.2.5, this case is no longer an issue:

  <Text sx={{"fontFamily": "\"Fira Code\", Menlo, Consolas, monospace"}}>
  {`broken`}
</Text>
  <Text sx={{"fontFamily": "'Fira Code', Menlo, Consolas, monospace"}}>
  {`working`}
</Text>

Note the quote escapes in the JSX now 😎

masenf avatar Aug 18 '23 15:08 masenf