Skip to content

fix: Fix pug-lexer parsed escaped interpolations incorrectly#3299

Merged
ForbesLindesay merged 3 commits intopugjs:masterfrom
shirohana:fix/lexer-incorrect-escaped-interpolation
Feb 28, 2021
Merged

fix: Fix pug-lexer parsed escaped interpolations incorrectly#3299
ForbesLindesay merged 3 commits intopugjs:masterfrom
shirohana:fix/lexer-incorrect-escaped-interpolation

Conversation

@shirohana
Copy link
Copy Markdown
Contributor

Pug-lexer always parsed escaped interpolations (\#{...} and \!{...}) into #{...}.

Here's the sample: https://runkit.com/shirohana/5f99255fb3cdb4001a711cf9

const { Lexer } = require('pug-lexer')

const code = `
p \\#{value}
p \\!{value}
`
const lexer = new Lexer(code, { filename: 'index.pug' })
const tokens = lexer.getTokens()
// Passed
assert(
  tokens[2].val === '#{value}',
  `1. expect "#{value}", actual: "${tokens[2].val}"`
)

// Throws
assert(
  tokens[5].val === '!{value}',
  `2. expect "!{value}", actual: "${tokens[5].val}"`
)

@rollingversions
Copy link
Copy Markdown

rollingversions bot commented Oct 28, 2020

pug-lexer (5.0.0 → 5.0.1)

Bug Fixes

  • Handle escaped unsafe interpolation correctly

    If you want to put the literal text #{ in your html, it needs to be escaped to indicate that it should not be treated as interpolation. The same is true of !{ You can escape them by prefixing them with \, e.g.

    p These are some \#{ weird \!{ symbols

    Previously this would have incorrectly converted both escaped sequences to #{, resulting in the html:

    <p>These are some #{ weird #{ symbols</p>

    Now this correctly generates:

    <p>These are some #{ weird !{ symbols</p>

Packages With No Changes

The following packages have no user facing changes, so won't be released:

  • pug
  • pug-attrs
  • pug-code-gen
  • pug-error
  • pug-filters
  • pug-linker
  • pug-load
  • pug-parser
  • pug-runtime
  • pug-strip-comments
  • pug-walk

Edit changelogs

@ForbesLindesay ForbesLindesay merged commit 29a53c5 into pugjs:master Feb 28, 2021
ngsctt pushed a commit to ngsctt/pug that referenced this pull request Feb 8, 2025
)

* fix: Fix escaped interpolation returning `#{}` but not `!{}`

* test: Update test case and snapshot of `pug-lexer/../interpolation.escape.pug`

* style: Fix prettier format
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.

2 participants