Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
Fix edge-case for boolean attributes in opening tags
Browse files Browse the repository at this point in the history
Fixes #49
  • Loading branch information
AlexVanderbist committed Oct 8, 2018
1 parent 82f803e commit 94d2f7d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-blade-x` will be documented in this file

## 2.0.1 - 2018-10-08

- fix edge-case for boolean attributes in opening tags

## 2.0.0 - 2018-10-08

- simplified component registration
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function parseOpeningTags(string $viewContents, Component $component):
{
$prefix = $this->bladeX->getPrefix();

$pattern = "/<\s*{$prefix}{$component->tag}(?<attributes>(?:\s+[\w\-:]+=(?:\\\"[^\\\"]+\\\"|\'[^\']+\'|[^\'\\\"=<>]+))*\s*)(?<![\/=\-])>/";
$pattern = "/<\s*{$prefix}{$component->tag}(?<attributes>(?:\s+[\w\-:]+(=(?:\\\"[^\\\"]+\\\"|\'[^\']+\'|[^\'\\\"=<>]+))?)*\s*)(?<![\/=\-])>/";

return preg_replace_callback($pattern, function (array $matches) use ($component) {
$attributes = $this->getAttributesFromAttributeString($matches['attributes']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<div>
<input type="checkbox" name="This one's checked" checked="checked"/>
<input type="checkbox" name="This one shouldn't be checked"/>
<input type="checkbox" name="" checked="checked"/>
</div>
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0"?>
<div>
<?php $__env->startComponent(
<div><?php $__env->startComponent(
'components.checkbox',
array_merge(app(Spatie\BladeX\ContextStack::class)->read(),
['name' => 'This one\'s checked','checked' => true])
); ?>
<?php echo $__env->renderComponent(); ?>
<?php $__env->startComponent(
); ?><?php echo $__env->renderComponent(); ?><?php $__env->startComponent(
'components.checkbox',
array_merge(app(Spatie\BladeX\ContextStack::class)->read(),
['name' => 'This one shouldn\'t be checked'])
); ?>
<?php echo $__env->renderComponent(); ?>
); ?><?php echo $__env->renderComponent(); ?><?php $__env->startComponent(
'components.checkbox',
array_merge(app(Spatie\BladeX\ContextStack::class)->read(),
['checked' => true])
); ?> content <?php echo $__env->renderComponent(); ?>
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<checkbox name="This one's checked" checked />

<checkbox name="This one shouldn't be checked" />

<checkbox checked>content</checkbox>

0 comments on commit 94d2f7d

Please sign in to comment.