framework: [8.x] Dynamic component HTML encodes props even when it shouldn't

  • Laravel Version: 8.2.0
  • PHP Version: 7.4.0
  • Database Driver & Version: irrelevant

Description:

The difference between :foo="$bar" and foo="{{ $bar }}" is that :foo doesn’t HTML-encode values. This is useful for passing raw strings to components such as the Trix editor.

However, when you use :foo="$bar" on a dynamic component, the value is encoded before being passed to the target component.

Steps To Reproduce:

Action:

Route::get('/', function () {
    return view('welcome', [
        'html' => '<div>abc</div>',
    ]);
});

View:

<html>
<head>
<body>
    :value <x-foo :value="$html" />
    mustache syntax <x-foo value="{{ $html }}" />
    dynamic component <x-dynamic-component component="foo" :value="$html" />
</body>
</head>

Component:

@props([
    'value',
])

<div>
    @dump($value)
</div>

Result: Screen Shot 2020-09-15 at 14 04 55

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 29 (26 by maintainers)

Most upvoted comments

For anyone encountering this in the future: When you’re accessing the value from the attribute bag, it will be encoded. Make sure you use @props().

Gonna re-open so @taylorotwell can check in on that.