Skip to content

Can't pass an escaped string literal into a component method with CSP version #4879

Closed

Description

@Roardom

Alpine.js version

v3.16.1

Browser and operating system

Firefox on Linux

Describe the issue you're experiencing

When passing an escaped string literal into an alpine component method, it is not parsed in the CSP version of alpine, but is parsed in the regular version.

The below example demonstrates this with two buttons: one that passes test and the other that passes tes\u0027t:

  • Passing test works fine for both versions.
  • Passing tes\u0027t results in tes't in the regular version, but tesu0027t in the CSP version.

This is particularly problematic when using laravel's Js::from() such as x-data="component({{ Js::from($test) }})"function, as it escapes apostrophes and other common symbols which get misread inside the component.

Code snippets to reproduce the issue

<!--<script src="https://unpkg.com/alpinejs" defer></script>-->
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/[email protected]/dist/cdn.min.js"></script>

<div x-data="test">
    <button x-on:click="set('test')">Without apostrophe (`test`)</button>
    <button x-on:click="set('tes\u0027t')">With apostrophe (`tes\u0027t`)</button>

    <input x-ref="input" />
</div>

<script>
  document.addEventListener('alpine:init', () => {
    Alpine.data('test', () => ({
      set(value) {
        this.$refs.input.value = value;
      }
    }))
  })
</script>

Screenshots/screen recordings

No response

How do you expect it to work?

I expect both the CSP and the non-CSP versions to handle escapes within literal strings passed into component constructors and methods.

Please confirm (incomplete submissions will not be addressed)

  • I have provided easy and step-by-step instructions to reproduce the bug.
  • I have provided code samples as text and NOT images.
  • I understand my bug report will be removed if I haven't met the criteria above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions