Skip to content

Commit 717aec6

Browse files
ISSUE #1498: Fix double quotes in heatmap route names
1 parent 7490d90 commit 717aec6

File tree

9 files changed

+34
-20
lines changed

9 files changed

+34
-20
lines changed

config/reference.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,17 @@
10951095
* doctrine?: DoctrineConfig,
10961096
* doctrine_migrations?: DoctrineMigrationsConfig,
10971097
* twig?: TwigConfig,
1098+
* "when@dev"?: array{
1099+
* imports?: ImportsConfig,
1100+
* parameters?: ParametersConfig,
1101+
* services?: ServicesConfig,
1102+
* framework?: FrameworkConfig,
1103+
* flysystem?: FlysystemConfig,
1104+
* monolog?: MonologConfig,
1105+
* doctrine?: DoctrineConfig,
1106+
* doctrine_migrations?: DoctrineMigrationsConfig,
1107+
* twig?: TwigConfig,
1108+
* },
10981109
* "when@prod"?: array{
10991110
* imports?: ImportsConfig,
11001111
* parameters?: ParametersConfig,
@@ -1197,6 +1208,7 @@ public static function config(array $config): array
11971208
* deprecated?: array{package:string, version:string, message?:string},
11981209
* }
11991210
* @psalm-type RoutesConfig = array{
1211+
* "when@dev"?: array<string, RouteConfig|ImportConfig|AliasConfig>,
12001212
* "when@prod"?: array<string, RouteConfig|ImportConfig|AliasConfig>,
12011213
* "when@test"?: array<string, RouteConfig|ImportConfig|AliasConfig>,
12021214
* ...<string, RouteConfig|ImportConfig|AliasConfig>

src/Domain/Activity/Activity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public function getName(): string
410410

411411
public function getSanitizedName(): string
412412
{
413-
return Escape::htmlSpecialChars($this->getName());
413+
return Escape::forJsonEncode($this->getName());
414414
}
415415

416416
public function updateName(string $name): self

src/Domain/Activity/GpxSerializer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public function serialize(ActivityId $activityId): ?string
5454
$metadataNode->addChild('time', $activity->getStartDate()->format(self::DATE_TIME_FORMAT));
5555

5656
$trkNode = $rootNode->addChild('trk');
57-
$trkNode->addChild('name', Escape::htmlSpecialChars($activity->getName()));
57+
$trkNode->addChild('name', Escape::forJsonEncode($activity->getName()));
5858
$trkNode->addChild('type', $activity->getSportType()->value);
5959
if ($description = $activity->getDescription()) {
60-
$trkNode->addChild('desc', Escape::htmlSpecialChars($description));
60+
$trkNode->addChild('desc', Escape::forJsonEncode($description));
6161
}
6262
$trksegNode = $trkNode->addChild('trkseg');
6363

src/Domain/Activity/Route/Route.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ public function jsonSerialize(): array
133133
'id' => $this->getActivityId(),
134134
'startDate' => $startDate,
135135
'distance' => $distance,
136-
'name' => Escape::htmlSpecialChars(str_replace(['"', '\''], '', $this->getName())), // Fix for ISSUE-1498
136+
'name' => Escape::forJsonEncode($this->getName()),
137137
'location' => [
138138
'countryCode' => $this->getLocation()->getCountryCode(),
139-
'state' => $state ? str_replace(['"', '\''], '', $state) : null, // Fix for ISSUE-287
139+
'state' => $state ? Escape::forJsonEncode($state) : null,
140140
],
141141
'filterables' => [
142142
'sportType' => $this->getSportType(),

src/Domain/Dashboard/Widget/TrainingLoad/TrainingLoadChart.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function build(): array
126126
'yAxis' => [
127127
[
128128
'type' => 'value',
129-
'name' => Escape::htmlSpecialChars($this->translator->trans('Daily TRIMP')),
129+
'name' => Escape::forJsonEncode($this->translator->trans('Daily TRIMP')),
130130
'nameLocation' => 'middle',
131131
'nameGap' => 35,
132132
'gridIndex' => 1,
@@ -137,7 +137,7 @@ public function build(): array
137137
],
138138
[
139139
'type' => 'value',
140-
'name' => Escape::htmlSpecialChars($this->translator->trans('Load (CTL/ATL)')),
140+
'name' => Escape::forJsonEncode($this->translator->trans('Load (CTL/ATL)')),
141141
'nameLocation' => 'middle',
142142
'nameGap' => 35,
143143
'gridIndex' => 0,
@@ -150,7 +150,7 @@ public function build(): array
150150
],
151151
[
152152
'type' => 'value',
153-
'name' => Escape::htmlSpecialChars($this->translator->trans('Form (TSB)')),
153+
'name' => Escape::forJsonEncode($this->translator->trans('Form (TSB)')),
154154
'nameLocation' => 'middle',
155155
'nameGap' => 35,
156156
'gridIndex' => 0,
@@ -166,7 +166,7 @@ public function build(): array
166166
],
167167
'series' => [
168168
[
169-
'name' => Escape::htmlSpecialChars($this->translator->trans('CTL (Fitness)')),
169+
'name' => Escape::forJsonEncode($this->translator->trans('CTL (Fitness)')),
170170
'type' => 'line',
171171
'data' => $this->trainingMetrics->getCtlValuesForXLastDays(self::NUMBER_OF_DAYS_TO_DISPLAY),
172172
'smooth' => true,
@@ -175,7 +175,7 @@ public function build(): array
175175
'yAxisIndex' => 1,
176176
],
177177
[
178-
'name' => Escape::htmlSpecialChars($this->translator->trans('ATL (Fatigue)')),
178+
'name' => Escape::forJsonEncode($this->translator->trans('ATL (Fatigue)')),
179179
'type' => 'line',
180180
'data' => $this->trainingMetrics->getAtlValuesForXLastDays(self::NUMBER_OF_DAYS_TO_DISPLAY),
181181
'smooth' => true,
@@ -184,7 +184,7 @@ public function build(): array
184184
'yAxisIndex' => 1,
185185
],
186186
[
187-
'name' => Escape::htmlSpecialChars($this->translator->trans('TSB (Form)')),
187+
'name' => Escape::forJsonEncode($this->translator->trans('TSB (Form)')),
188188
'type' => 'line',
189189
'data' => $tsbValues,
190190
'smooth' => true,
@@ -200,21 +200,21 @@ public function build(): array
200200
'data' => [
201201
[
202202
'yAxis' => 15,
203-
'label' => ['formatter' => Escape::htmlSpecialChars($this->translator->trans('Taper sweet-spot (+15)'))],
203+
'label' => ['formatter' => Escape::forJsonEncode($this->translator->trans('Taper sweet-spot (+15)'))],
204204
],
205205
[
206206
'yAxis' => -10,
207-
'label' => ['formatter' => Escape::htmlSpecialChars($this->translator->trans('Build zone (–10)'))],
207+
'label' => ['formatter' => Escape::forJsonEncode($this->translator->trans('Build zone (–10)'))],
208208
],
209209
[
210210
'yAxis' => -30,
211-
'label' => ['formatter' => Escape::htmlSpecialChars($this->translator->trans('Over-fatigued (–30)'))],
211+
'label' => ['formatter' => Escape::forJsonEncode($this->translator->trans('Over-fatigued (–30)'))],
212212
],
213213
],
214214
],
215215
],
216216
[
217-
'name' => Escape::htmlSpecialChars($this->translator->trans('Daily TRIMP')),
217+
'name' => Escape::forJsonEncode($this->translator->trans('Daily TRIMP')),
218218
'type' => 'bar',
219219
'data' => $this->trainingMetrics->getTrimpValuesForXLastDays(self::NUMBER_OF_DAYS_TO_DISPLAY),
220220
'itemStyle' => ['color' => '#FC4C02'],

src/Domain/Gear/DistanceOverTimePerGearChart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function build(): array
7373
$selectedSeries = [];
7474
/** @var Gear $gear */
7575
foreach ($gears as $gear) {
76-
$gearName = Escape::htmlSpecialChars($gear->getName());
76+
$gearName = Escape::forJsonEncode($gear->getName());
7777
$selectedSeries[$gearName] = !$gear->isRetired();
7878

7979
$series[] = [

src/Domain/Gear/DistancePerMonthPerGearChart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function build(): array
7171
$unitSymbol = $this->unitSystem->distanceSymbol();
7272

7373
foreach ($gears as $gear) {
74-
$gearName = Escape::htmlSpecialChars($gear->getName());
74+
$gearName = Escape::forJsonEncode($gear->getName());
7575
$distanceInLastThreeMonths = array_sum(array_slice($distancePerGearAndMonth[(string) $gear->getId()], -3, 3));
7676
$selectedSeries[$gearName] = $distanceInLastThreeMonths > 0;
7777

src/Domain/Gear/MovingTimePerGearChart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function build(): array
4141
}
4242
$data[] = [
4343
'value' => round($time / 3600),
44-
'name' => Escape::htmlSpecialChars($gear->getName()),
44+
'name' => Escape::forJsonEncode($gear->getName()),
4545
'itemStyle' => [
4646
'color' => Theme::getColorForGear($gear->getId()),
4747
],

src/Infrastructure/Serialization/Escape.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
final readonly class Escape
88
{
9-
public static function htmlSpecialChars(string $string): string
9+
public static function forJsonEncode(string $string): string
1010
{
11-
return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
11+
return $string
12+
|> (fn (string $value): string => str_replace(['"', '\''], '', $value))
13+
|> (fn (string $value): string => htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'));
1214
}
1315
}

0 commit comments

Comments
 (0)