Skip to content

Commit 34deb47

Browse files
committed
Revert "[StimulusBundle] Revert to html_attr escaping strategy (because of BC), rollback tests too"
This reverts commit 4529b87.
1 parent 27a8660 commit 34deb47

File tree

10 files changed

+26
-28
lines changed

10 files changed

+26
-28
lines changed

Diff for: src/Chartjs/tests/Twig/ChartExtensionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testRenderChart()
5656
);
5757

5858
$this->assertSame(
59-
'<canvas data-controller="mycontroller symfony--ux-chartjs--chart" data-symfony--ux-chartjs--chart-view-value="&#x7B;&quot;type&quot;&#x3A;&quot;line&quot;,&quot;data&quot;&#x3A;&#x7B;&quot;labels&quot;&#x3A;&#x5B;&quot;January&quot;,&quot;February&quot;,&quot;March&quot;,&quot;April&quot;,&quot;May&quot;,&quot;June&quot;,&quot;July&quot;&#x5D;,&quot;datasets&quot;&#x3A;&#x5B;&#x7B;&quot;label&quot;&#x3A;&quot;My&#x20;First&#x20;dataset&quot;,&quot;backgroundColor&quot;&#x3A;&quot;rgb&#x28;255,&#x20;99,&#x20;132&#x29;&quot;,&quot;borderColor&quot;&#x3A;&quot;rgb&#x28;255,&#x20;99,&#x20;132&#x29;&quot;,&quot;data&quot;&#x3A;&#x5B;0,10,5,2,20,30,45&#x5D;&#x7D;&#x5D;&#x7D;,&quot;options&quot;&#x3A;&#x7B;&quot;showLines&quot;&#x3A;false&#x7D;&#x7D;" class="myclass"></canvas>',
59+
'<canvas data-controller="mycontroller symfony--ux-chartjs--chart" data-symfony--ux-chartjs--chart-view-value="{&quot;type&quot;:&quot;line&quot;,&quot;data&quot;:{&quot;labels&quot;:[&quot;January&quot;,&quot;February&quot;,&quot;March&quot;,&quot;April&quot;,&quot;May&quot;,&quot;June&quot;,&quot;July&quot;],&quot;datasets&quot;:[{&quot;label&quot;:&quot;My First dataset&quot;,&quot;backgroundColor&quot;:&quot;rgb(255, 99, 132)&quot;,&quot;borderColor&quot;:&quot;rgb(255, 99, 132)&quot;,&quot;data&quot;:[0,10,5,2,20,30,45]}]},&quot;options&quot;:{&quot;showLines&quot;:false}}" class="myclass"></canvas>',
6060
$rendered
6161
);
6262
}

Diff for: src/LiveComponent/tests/Unit/Twig/LiveComponentRuntimeTest.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@ public function testGetLiveAction(): void
2828
$this->assertSame('data-action="live#action" data-live-prop1-param="val1" data-live-some-prop-param="val2" data-live-action-param="action-name"', $props);
2929

3030
$props = $runtime->liveAction('action-name', ['prop1' => 'val1', 'prop2' => 'val2'], ['debounce' => 300]);
31-
$this->assertSame('data-action="live#action" data-live-prop1-param="val1" data-live-prop2-param="val2" data-live-action-param="debounce(300)|action-name"', html_entity_decode($props));
32-
$this->assertSame('data-action="live#action" data-live-prop1-param="val1" data-live-prop2-param="val2" data-live-action-param="debounce&#x28;300&#x29;&#x7C;action-name"', $props);
31+
$this->assertSame('data-action="live#action" data-live-prop1-param="val1" data-live-prop2-param="val2" data-live-action-param="debounce(300)|action-name"', $props);
3332

3433
$props = $runtime->liveAction('action-name:prevent', ['pro1' => 'val1', 'prop2' => 'val2'], ['debounce' => 300]);
35-
$this->assertSame('data-action="live#action:prevent" data-live-pro1-param="val1" data-live-prop2-param="val2" data-live-action-param="debounce(300)|action-name"', html_entity_decode($props));
36-
$this->assertSame('data-action="live#action&#x3A;prevent" data-live-pro1-param="val1" data-live-prop2-param="val2" data-live-action-param="debounce&#x28;300&#x29;&#x7C;action-name"', $props);
34+
$this->assertSame('data-action="live#action:prevent" data-live-pro1-param="val1" data-live-prop2-param="val2" data-live-action-param="debounce(300)|action-name"', $props);
3735

3836
$props = $runtime->liveAction('action-name:prevent', [], ['debounce' => 300]);
39-
$this->assertSame('data-action="live#action:prevent" data-live-action-param="debounce(300)|action-name"', html_entity_decode($props));
37+
$this->assertSame('data-action="live#action:prevent" data-live-action-param="debounce(300)|action-name"', $props);
4038

4139
$props = $runtime->liveAction('action-name', [], [], 'keydown.esc');
42-
$this->assertSame('data-action="keydown.esc->live#action" data-live-action-param="action-name"', html_entity_decode($props));
40+
$this->assertSame('data-action="keydown.esc->live#action" data-live-action-param="action-name"', $props);
4341
}
4442
}

Diff for: src/Notify/tests/Twig/NotifyRuntimeTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public function testStreamNotifications(array $params, string $expected)
3939

4040
public static function streamNotificationsDataProvider(): iterable
4141
{
42-
$publicUrl = 'http&#x3A;&#x2F;&#x2F;localhost&#x3A;9090&#x2F;.well-known&#x2F;mercure';
42+
$publicUrl = 'http://localhost:9090/.well-known/mercure';
4343

4444
yield [
4545
[['/topic/1', '/topic/2']],
4646
'<div '.
4747
'data-controller="symfony--ux-notify--notify" '.
48-
'data-symfony--ux-notify--notify-topics-value="&#x5B;&quot;&#x5C;&#x2F;topic&#x5C;&#x2F;1&quot;,&quot;&#x5C;&#x2F;topic&#x5C;&#x2F;2&quot;&#x5D;" '.
48+
'data-symfony--ux-notify--notify-topics-value="[&quot;\/topic\/1&quot;,&quot;\/topic\/2&quot;]" '.
4949
'data-symfony--ux-notify--notify-hub-value="'.$publicUrl.'"'.
5050
'></div>',
5151
];
@@ -54,7 +54,7 @@ public static function streamNotificationsDataProvider(): iterable
5454
['/topic/1'],
5555
'<div '.
5656
'data-controller="symfony--ux-notify--notify" '.
57-
'data-symfony--ux-notify--notify-topics-value="&#x5B;&quot;&#x5C;&#x2F;topic&#x5C;&#x2F;1&quot;&#x5D;" '.
57+
'data-symfony--ux-notify--notify-topics-value="[&quot;\/topic\/1&quot;]" '.
5858
'data-symfony--ux-notify--notify-hub-value="'.$publicUrl.'"'.
5959
'></div>',
6060
];
@@ -63,7 +63,7 @@ public static function streamNotificationsDataProvider(): iterable
6363
[],
6464
'<div '.
6565
'data-controller="symfony--ux-notify--notify" '.
66-
'data-symfony--ux-notify--notify-topics-value="&#x5B;&quot;https&#x3A;&#x5C;&#x2F;&#x5C;&#x2F;symfony.com&#x5C;&#x2F;notifier&quot;&#x5D;" '.
66+
'data-symfony--ux-notify--notify-topics-value="[&quot;https:\/\/symfony.com\/notifier&quot;]" '.
6767
'data-symfony--ux-notify--notify-hub-value="'.$publicUrl.'"'.
6868
'></div>',
6969
];

Diff for: src/React/tests/Twig/ReactComponentExtensionTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testRenderComponent()
3636
);
3737

3838
$this->assertSame(
39-
'data-controller="symfony--ux-react--react" data-symfony--ux-react--react-component-value="SubDir&#x2F;MyComponent" data-symfony--ux-react--react-props-value="&#x7B;&quot;fullName&quot;&#x3A;&quot;Titouan&#x20;Galopin&quot;&#x7D;"',
39+
'data-controller="symfony--ux-react--react" data-symfony--ux-react--react-component-value="SubDir/MyComponent" data-symfony--ux-react--react-props-value="{&quot;fullName&quot;:&quot;Titouan Galopin&quot;}"',
4040
$rendered
4141
);
4242
}
@@ -52,7 +52,7 @@ public function testRenderComponentWithoutProps()
5252
$rendered = $extension->renderReactComponent('SubDir/MyComponent');
5353

5454
$this->assertSame(
55-
'data-controller="symfony--ux-react--react" data-symfony--ux-react--react-component-value="SubDir&#x2F;MyComponent"',
55+
'data-controller="symfony--ux-react--react" data-symfony--ux-react--react-component-value="SubDir/MyComponent"',
5656
$rendered
5757
);
5858
}

Diff for: src/StimulusBundle/src/Dto/StimulusAttributes.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function __toString(): string
110110
$attributes = [];
111111

112112
if ($this->controllers) {
113-
$attributes[] = 'data-controller="'.implode(' ', array_map(fn (string $controller) => $this->escape($controller, 'html_attr'), $this->controllers)).'"';
113+
$attributes[] = 'data-controller="'.$this->escape(implode(' ', $this->controllers), 'html').'"';
114114
}
115115

116116
if ($this->actions) {
@@ -120,9 +120,9 @@ public function __toString(): string
120120
$actionName = $actionData['actionName'];
121121
$eventName = $actionData['eventName'];
122122

123-
$action = $this->escape($controllerName, 'html_attr').'#'.$this->escape($actionName, 'html_attr');
123+
$action = $this->escape($controllerName.'#'.$actionName, 'html');
124124
if (null !== $eventName) {
125-
$action = $this->escape($eventName, 'html_attr').'->'.$action;
125+
$action = $this->escape($eventName, 'html').'->'.$action;
126126
}
127127

128128
return $action;
@@ -133,13 +133,13 @@ public function __toString(): string
133133

134134
if ($this->targets) {
135135
$attributes[] = implode(' ', array_map(function (string $key, string $value): string {
136-
return $key.'="'.implode(' ', array_map(fn (string $target) => $this->escape($target, 'html_attr'), explode(' ', $value))).'"';
136+
return $this->escape($key, 'html_attr').'="'.$this->escape($value, 'html').'"';
137137
}, array_keys($this->targets), $this->targets));
138138
}
139139

140140
if ($this->attributes) {
141141
$attributes[] = implode(' ', array_map(function (string $attribute, string $value): string {
142-
return $attribute.'="'.$this->escape($value, 'html_attr').'"';
142+
return $this->escape($attribute, 'html_attr').'="'.$this->escape($value, 'html').'"';
143143
}, array_keys($this->attributes), $this->attributes));
144144
}
145145

@@ -182,7 +182,7 @@ public function toEscapedArray(): array
182182
{
183183
$escaped = [];
184184
foreach ($this->toArray() as $key => $value) {
185-
$escaped[$key] = $this->escape($value, 'html_attr');
185+
$escaped[$key] = $this->escape($value, 'html');
186186
}
187187

188188
return $escaped;

Diff for: src/StimulusBundle/tests/Dto/StimulusAttributesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function testIsTraversable()
145145
public function testAddAttribute()
146146
{
147147
$this->stimulusAttributes->addAttribute('foo', 'bar baz');
148-
$this->assertSame('foo="bar&#x20;baz"', (string) $this->stimulusAttributes);
148+
$this->assertSame('foo="bar baz"', (string) $this->stimulusAttributes);
149149
$this->assertSame(['foo' => 'bar baz'], $this->stimulusAttributes->toArray());
150150
}
151151
}

Diff for: src/StimulusBundle/tests/Twig/StimulusTwigExtensionTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public function testAppendStimulusController(): void
135135
$extension = new StimulusTwigExtension(new StimulusHelper($this->twig));
136136
$dto = $extension->renderStimulusController('my-controller', ['myValue' => 'scalar-value']);
137137
$this->assertSame(
138-
'data-controller="my-controller another-controller" data-my-controller-my-value-value="scalar-value" data-another-controller-another-value-value="scalar-value&#x20;2"',
139-
(string) $extension->appendStimulusController($dto, 'another-controller', ['another-value' => 'scalar-value 2']),
138+
'data-controller="my-controller another-controller" data-my-controller-my-value-value="scalar-value" data-another-controller-another-value-value="scalar-value 2" data-another-controller-json-value-value="{&quot;key&quot;:&quot;Value with quotes &#039; and \&quot;.&quot;}"',
139+
(string) $extension->appendStimulusController($dto, 'another-controller', ['another-value' => 'scalar-value 2', 'jsonValue' => json_encode(['key' => 'Value with quotes \' and ".'])]),
140140
);
141141
}
142142

Diff for: src/Svelte/tests/Twig/SvelteComponentExtensionTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testRenderComponent()
3737
);
3838

3939
$this->assertSame(
40-
'data-controller="symfony--ux-svelte--svelte" data-symfony--ux-svelte--svelte-component-value="SubDir&#x2F;MyComponent" data-symfony--ux-svelte--svelte-props-value="&#x7B;&quot;fullName&quot;&#x3A;&quot;Titouan&#x20;Galopin&quot;&#x7D;"',
40+
'data-controller="symfony--ux-svelte--svelte" data-symfony--ux-svelte--svelte-component-value="SubDir/MyComponent" data-symfony--ux-svelte--svelte-props-value="{&quot;fullName&quot;:&quot;Titouan Galopin&quot;}"',
4141
$rendered
4242
);
4343
}
@@ -53,7 +53,7 @@ public function testRenderComponentWithoutProps()
5353
$rendered = $extension->renderSvelteComponent('SubDir/MyComponent');
5454

5555
$this->assertSame(
56-
'data-controller="symfony--ux-svelte--svelte" data-symfony--ux-svelte--svelte-component-value="SubDir&#x2F;MyComponent"',
56+
'data-controller="symfony--ux-svelte--svelte" data-symfony--ux-svelte--svelte-component-value="SubDir/MyComponent"',
5757
$rendered
5858
);
5959
}
@@ -73,7 +73,7 @@ public function testRenderComponentWithIntro()
7373
);
7474

7575
$this->assertSame(
76-
'data-controller="symfony--ux-svelte--svelte" data-symfony--ux-svelte--svelte-component-value="SubDir&#x2F;MyComponent" data-symfony--ux-svelte--svelte-props-value="&#x7B;&quot;fullName&quot;&#x3A;&quot;Titouan&#x20;Galopin&quot;&#x7D;" data-symfony--ux-svelte--svelte-intro-value="true"',
76+
'data-controller="symfony--ux-svelte--svelte" data-symfony--ux-svelte--svelte-component-value="SubDir/MyComponent" data-symfony--ux-svelte--svelte-props-value="{&quot;fullName&quot;:&quot;Titouan Galopin&quot;}" data-symfony--ux-svelte--svelte-intro-value="true"',
7777
$rendered
7878
);
7979
}

Diff for: src/TwigComponent/tests/Unit/ComponentAttributesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function testCanAddStimulusControllerViaStimulusAttributes(): void
147147
'data-controller' => 'foo live',
148148
'data-live-data-value' => '{}',
149149
'data-foo-name-value' => 'ryan',
150-
'data-foo-some-array-value' => '&#x5B;&quot;a&quot;,&quot;b&quot;&#x5D;',
150+
'data-foo-some-array-value' => '[&quot;a&quot;,&quot;b&quot;]',
151151
], $attributes->all());
152152
}
153153

Diff for: src/Vue/tests/Twig/VueComponentExtensionTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testRenderComponent()
3737
);
3838

3939
$this->assertSame(
40-
'data-controller="symfony--ux-vue--vue" data-symfony--ux-vue--vue-component-value="SubDir&#x2F;MyComponent" data-symfony--ux-vue--vue-props-value="&#x7B;&quot;fullName&quot;&#x3A;&quot;Titouan&#x20;Galopin&quot;&#x7D;"',
40+
'data-controller="symfony--ux-vue--vue" data-symfony--ux-vue--vue-component-value="SubDir/MyComponent" data-symfony--ux-vue--vue-props-value="{&quot;fullName&quot;:&quot;Titouan Galopin&quot;}"',
4141
$rendered
4242
);
4343
}
@@ -53,7 +53,7 @@ public function testRenderComponentWithoutProps()
5353
$rendered = $extension->renderVueComponent('SubDir/MyComponent');
5454

5555
$this->assertSame(
56-
'data-controller="symfony--ux-vue--vue" data-symfony--ux-vue--vue-component-value="SubDir&#x2F;MyComponent"',
56+
'data-controller="symfony--ux-vue--vue" data-symfony--ux-vue--vue-component-value="SubDir/MyComponent"',
5757
$rendered
5858
);
5959
}

0 commit comments

Comments
 (0)