Skip to content

Ensure strings in Pug and Slim templates are handled correctly #17000

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

Merged
merged 5 commits into from
Mar 6, 2025

Conversation

RobinMalfait
Copy link
Member

This PR fixes an issue where strings in the Pug and Slim pre-processor were handled using the string_machine. However, the string_machine is not for strings inside of Tailwind CSS classes which means that whitespace is invalid.

This means that parts of the code that are inside strings will not be inside strings and parts of the code that are not inside strings will be part of a potential string. This is a bit confusing to wrap your head around, but here is a visual representation of the problem:

.join(' ')
        ^  3. start of new string, which means that the `)` _could_ be part of a string if a new `'` occurs later.
       ^   2. whitespace is not allowed, stop string
      ^    1. start of string

Fixes: #16998

Test plan

  1. Added new test
  2. Existing tests still pass
  3. Added a simple test helper to make sure that we can extract the correct candidates after pre-processing

The problem here is that our internal `string_machine` is about strings
in Tailwind utilities. This means that spaces are not allowed, but we
can't use that in this context otherwise a string like this:

```
.join(' ')
        ^  3. start of new string
       ^   2. whitespace is not allowed, stop string
      ^    1. start of string
```

This could result in parts of the code to be considered a string when
it's clearly not.

Instead, we will use a custom string consumer implementation that just
keeps reading until the end of the string.
This allows us to run the pre processor and then run the extractor to
ensure at least the correct items are extracted that we expect.
@RobinMalfait RobinMalfait requested a review from a team as a code owner March 6, 2025 16:18
@RobinMalfait RobinMalfait merged commit 85c6e04 into main Mar 6, 2025
5 checks passed
@RobinMalfait RobinMalfait deleted the fix/issue-16998 branch March 6, 2025 16:24
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.

4.0.11 - Regression with SLIM templates (nested brackets)
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy