Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape quotes bug #109

Open
7iomka opened this issue Jul 22, 2021 · 1 comment
Open

Escape quotes bug #109

7iomka opened this issue Jul 22, 2021 · 1 comment

Comments

@7iomka
Copy link

7iomka commented Jul 22, 2021

Example from docs with same quote interpolation

div(placeholder="{{ 'I\'m best of the best' | translate }}")

get me error

Trace: SyntaxError: Unexpected token, when trying to parse `{{ 'I'm best of the best' | translate }}`

I would like to know why I am getting errorsfor this case.
Thanks

PS: I think solution, but problem from above is a bug.

My solution:

  1. Excape self-made
placeholder="{{ "I'm best of the best" | translate }}"
  1. Auto escape by pug
placeholder=`{{ "I\'m best of the best" | translate }}`

BUT
My solution not working as needed if we have 2 types of quotes

placeholder=`{{ "I\'m best of the \"best\"" | translate }}`

That extract

msgid "I'm best of the "best""

instead of

msgid "I'm best of the \"best\""

How to fix this issues?
Thanks!

@7iomka 7iomka changed the title Allow backticks for strings with quotes Escape quotes bug Jul 22, 2021
@7iomka
Copy link
Author

7iomka commented Jul 22, 2021

My tests for translate attributes in pug

  • default (with escape enabled (=)) Works FINE
div(content= `{{ "${meta.description}" | t }}`)
  • default (with escape disabled (!=)) THIS CAUSE ALWAYS WRONG output
div(content!= `{{ "${meta.description}" | t }}`)

If variable contains interpolated SINGLE quotes '
Code below will throw

  SyntaxError: Unexpected token, when trying to parse `{{ 'te434343x'st' | t }}`
div(content=`{{ '${meta.description}' | t }}`)
div(content!=`{{ '${meta.description}' | t }}`)

If we use for code above DOUBLE quotes, error will disappear, but extraction output will be WRONG with unescaped output(!=).

div(content!=`{{ "${meta.description}" | t }}`)

Recap: If string has interpolated single quotes('), SyntaxError will occur for both (unescaped & escaped) assignments, if that wrapped also in a SINGLE quote!
USE double quote with escaped mode (=);

div(content= `{{ "${meta.description}" | t }}`)

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

No branches or pull requests

1 participant