Skip to content

Components: The ")" character, this may cause an error #36815

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

Closed
mxgrim opened this issue Mar 30, 2021 · 6 comments · Fixed by #36843
Closed

Components: The ")" character, this may cause an error #36815

mxgrim opened this issue Mar 30, 2021 · 6 comments · Fixed by #36843
Labels

Comments

@mxgrim
Copy link

mxgrim commented Mar 30, 2021

  • Laravel Version: 8.34.0
  • PHP Version: 7.4.16
  • Database Driver & Version: -

Description:

If you use the ")" character in a declared attribute of a component, this will result in an error:
ParseError
syntax error, unexpected ..

Steps To Reproduce:

Declare an attribute on a component:
public function __construct($title = '')

Run from any .blade.php:
<x-forms.input title="test test )"/>

@selcukcukur
Copy link
Contributor

Can you share all the codes you use exactly because I have not encountered such a problem, you may be making a mistake while using it. @mxgrim

@selcukcukur
Copy link
Contributor

I think this is a problem caused by a user error. I applied the necessary tests, but I did not encounter the same error. @driesvints

@mxgrim
Copy link
Author

mxgrim commented Mar 31, 2021

app/View/Components/Forms/Test.php

<?php

namespace App\View\Components\Forms;

use Illuminate\View\Component;

class Test extends Component
{
    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct($test = '')
    {
        //
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {
        return view('components.forms.test');
    }
}

resourses/views/components/forms/test.blade.php

<div>
    test
</div>

resourses/views/index.blade.php

<x-forms.test test=")"/>


Error:

ParseError
syntax error, unexpected 'forms' (T_STRING), expecting ']'

Compiled file (storage/framework/views/...):

<?php if (isset($component)) { $__componentOriginal40e62d942e0a3dbd05627ad21d1c6a1a4a3b111f = $component; } ?>
<?php $component = $__env->getContainer()->make(App\View\Components\Forms\Test::class, ['test' => '); ?>
<?php $component->withName('forms.test'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>'])
<?php $component->withAttributes([]); ?>
<?php if (isset($__componentOriginal40e62d942e0a3dbd05627ad21d1c6a1a4a3b111f)): ?>
<?php $component = $__componentOriginal40e62d942e0a3dbd05627ad21d1c6a1a4a3b111f; ?>
<?php unset($__componentOriginal40e62d942e0a3dbd05627ad21d1c6a1a4a3b111f); ?>
<?php endif; ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>

The problem is here:
make(App\View\Components\Forms\Test::class, ['test' => '); ?>

@selcukcukur
Copy link
Contributor

selcukcukur commented Mar 31, 2021

[$component, $alias, $data] = strpos($expression, ',') !== false

? array_map('trim', explode(',', trim($expression, '()'), 3)) + ['', '', '']

The problem is here. I'm sending a pull request.

@driesvints driesvints added the bug label Apr 1, 2021
@driesvints
Copy link
Member

I've tracked it down to compileStatements in BladeCompiler which incorrectly removes the ']) part at the end. Currently trying to see if I can adjust the regex.

@driesvints
Copy link
Member

Here's a PR with a failing test: #36843

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants