Skip to content

Support semicolon-separated expressions in the CSP evaluator - #4915

Open
m-develops wants to merge 1 commit into
alpinejs:mainfrom
m-develops:csp-expression-sequences
Open

m-develops wants to merge 1 commit into
alpinejs:mainfrom
m-develops:csp-expression-sequences

Conversation

@m-develops

Copy link
Copy Markdown

The CSP evaluator accepts one expression per attribute. A handler such as count++; open = true, which needs no evaluation of anything beyond what the evaluator already allows, has to be moved into a component method under the CSP build.

Why now. Livewire's csp_safe mode uses this build, and Filament is working on supporting it. Filament's afterStateUpdatedJs() hooks are user-supplied strings of one or two expressions that Dan Harrin wants evaluated through this evaluator from bundled code instead of through new Function(): filamentphp/filament#7032 (reply in thread)

What this does. parse() reads expressions separated by semicolons. They are evaluated in order in the same scope, and the value of the last one is the result, so a later expression sees what an earlier one assigned. A single expression parses to the same tree as before, a trailing semicolon stays allowed, and empty expressions between separators (a;;b) are rejected. No statements, no declarations, no control flow: only the expressions the evaluator already accepts, one after the other.

Unit tests, a Cypress test, and a docs entry.

The CSP build's parser accepted one expression and an optional trailing
semicolon, so an event handler such as `count++; open = true` had to be
moved into a component method.

`parse()` now reads expressions separated by semicolons. They are
evaluated in order and the value of the last one is the result, so a
later expression sees what an earlier one assigned. A single expression
parses to the same tree as before, empty expressions between separators
are rejected, and a trailing semicolon stays allowed.

This branch has not been deployed

No deployments
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