Skip to content

Commit c89a7a9

Browse files
committed
refactor: unblocked against laravel#57467
1 parent 77a29b1 commit c89a7a9

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

src/Illuminate/View/ComponentAttributeBag.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,25 +491,14 @@ public function __toString()
491491
continue;
492492
}
493493

494-
// Empty "alt" explicitly marks an image as decorative; empty "value" and "data-*"
495-
// are valid. For everything else we don't want to render the attribute at all.
496-
if (!in_array($key, ['alt', 'value']) && !str_starts_with($key, 'data') && (is_string($value) && trim($value) === '')) {
497-
continue;
498-
}
499-
500494
if ($value === true) {
501495
$value = $key === 'x-data' || str_starts_with($key, 'wire:') ? '' : $key;
502496
}
503497

504-
// Same as above. We want everything but data and value to be trimmed
505-
$value = !str_starts_with($key, 'data') && $key !== 'value'
506-
? trim($value)
507-
: $value;
508-
509498
if($key === $value) {
510499
$string .= ' '.$key;
511500
} else {
512-
$string .= ' '.$key.'="'.str_replace('"', '\\"', $value).'"';
501+
$string .= ' ' . $key . '="' . str_replace('"', '\\"', trim($value)) . '"';
513502
}
514503
}
515504

tests/View/ViewComponentAttributeBagTest.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,10 @@ public function testAttributeRetrieval()
5151
'test-0' => 0,
5252
'test-0-string' => '0',
5353
'test-empty-string' => '',
54-
'test-whitespace-string' => ' ',
55-
'data-test-empty-string' => '',
56-
'data-test-whitespace-string' => ' ',
57-
'value' => ' ',
58-
'alt' => '',
5954
]);
6055

61-
$this->assertSame('test-string="ok" test-true test-0="0" test-0-string="0" data-test-empty-string="" data-test-whitespace-string=" " value=" " alt=""', (string) $bag);
62-
$this->assertSame('test-string="ok" test-true test-0="0" test-0-string="0" data-test-empty-string="" data-test-whitespace-string=" " value=" " alt=""', (string) $bag->merge());
56+
$this->assertSame('test-string="ok" test-true test-0="0" test-0-string="0" test-empty-string=""', (string) $bag);
57+
$this->assertSame('test-string="ok" test-true test-0="0" test-0-string="0" test-empty-string=""', (string) $bag->merge());
6358

6459
$bag = (new ComponentAttributeBag)
6560
->merge([
@@ -77,14 +72,10 @@ public function testAttributeRetrieval()
7772
'test-0' => 0,
7873
'test-0-string' => '0',
7974
'test-empty-string' => '',
80-
'test-whitespace-string' => ' ',
81-
'data-test-empty-string' => '',
82-
'data-test-whitespace-string' => ' ',
83-
'value' => ' ',
84-
'alt' => '',
8575
]);
8676

87-
$this->assertSame('test-string="ok" test-true test-0="0" test-0-string="0" data-test-empty-string="" data-test-whitespace-string=" " value=" " alt=""', (string) $bag);
77+
$this->assertSame('test-string="ok" test-true test-0="0" test-0-string="0" test-empty-string=""', (string) $bag);
78+
8879
$bag = (new ComponentAttributeBag)
8980
->merge([
9081
'test-extract-1' => 'extracted-1',

0 commit comments

Comments
 (0)