Skip to content

Commit 41f886c

Browse files
committed
Merge branch '3.4-release'
2 parents 36ae70a + 59daf9a commit 41f886c

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

bundle/Controller/Admin/FieldController.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
use function array_keys;
1313
use function array_values;
1414
use function count;
15+
use function htmlspecialchars;
1516
use function in_array;
17+
use const ENT_HTML401;
18+
use const ENT_QUOTES;
19+
use const ENT_SUBSTITUTE;
1620

1721
final class FieldController extends Controller
1822
{
@@ -99,8 +103,8 @@ private function filterTags(TagList $tags, int $subTreeLimit, bool $hideRootTag)
99103

100104
$data[] = [
101105
'parent_id' => $tag->parentTagId,
102-
'parent_name' => count($parentTagKeywords) > 0 ? array_values($parentTagKeywords)[0] : '',
103-
'name' => array_values($tagKeywords)[0],
106+
'parent_name' => count($parentTagKeywords) > 0 ? $this->escape(array_values($parentTagKeywords)[0]) : '',
107+
'name' => $this->escape(array_values($tagKeywords)[0]),
104108
'id' => $tag->id,
105109
'main_tag_id' => $tag->mainTagId,
106110
'locale' => array_keys($tagKeywords)[0],
@@ -109,4 +113,9 @@ private function filterTags(TagList $tags, int $subTreeLimit, bool $hideRootTag)
109113

110114
return $data;
111115
}
116+
117+
private function escape($string): string
118+
{
119+
return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8');
120+
}
112121
}

bundle/Controller/Admin/TreeController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
use Symfony\Component\HttpFoundation\JsonResponse;
1111
use Symfony\Component\Routing\RouterInterface;
1212
use Symfony\Contracts\Translation\TranslatorInterface;
13+
use function htmlspecialchars;
1314
use function str_replace;
15+
use const ENT_HTML401;
16+
use const ENT_QUOTES;
17+
use const ENT_SUBSTITUTE;
1418

1519
final class TreeController extends Controller
1620
{
@@ -148,7 +152,7 @@ private function getTagTreeData(Tag $tag, bool $isRoot = false): array
148152
return [
149153
'id' => $tag->id,
150154
'parent' => $isRoot ? '#' : $tag->parentTagId,
151-
'text' => $synonymCount > 0 ? $tag->keyword . ' (+' . $synonymCount . ')' : $tag->keyword,
155+
'text' => $synonymCount > 0 ? $this->escape($tag->keyword) . ' (+' . $synonymCount . ')' : $this->escape($tag->keyword),
152156
'children' => $this->tagsService->getTagChildrenCount($tag) > 0,
153157
'a_attr' => [
154158
'href' => str_replace(':tagId', (string) $tag->id, $this->treeLinks['show_tag']),
@@ -193,4 +197,9 @@ private function getTagTreeData(Tag $tag, bool $isRoot = false): array
193197
],
194198
];
195199
}
200+
201+
private function escape($string): string
202+
{
203+
return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8');
204+
}
196205
}

bundle/Form/Type/FieldType/FieldValueTransformer.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
use function array_key_exists;
1212
use function count;
1313
use function explode;
14+
use function htmlspecialchars;
1415
use function implode;
16+
use const ENT_HTML401;
17+
use const ENT_QUOTES;
18+
use const ENT_SUBSTITUTE;
1519

1620
final class FieldValueTransformer implements DataTransformerInterface
1721
{
@@ -51,7 +55,7 @@ public function transform($value): ?array
5155

5256
$ids[] = $tag->id;
5357
$parentIds[] = $tag->parentTagId;
54-
$keywords[] = $tagKeyword ?? $mainKeyword;
58+
$keywords[] = $this->escape($tagKeyword ?? $mainKeyword);
5559
$locales[] = $tagKeyword !== null ? $this->field->languageCode : $tag->mainLanguageCode;
5660
}
5761

@@ -91,11 +95,16 @@ public function reverseTransform($value): Value
9195

9296
$hash[] = [
9397
'parent_id' => (int) $parentIds[$i],
94-
'keywords' => [$locales[$i] => $keywords[$i]],
98+
'keywords' => [$locales[$i] => $this->escape($keywords[$i])],
9599
'main_language_code' => $locales[$i],
96100
];
97101
}
98102

99103
return $this->fieldType->fromHash($hash);
100104
}
105+
106+
private function escape($string): string
107+
{
108+
return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8');
109+
}
101110
}

0 commit comments

Comments
 (0)