Skip to content

Commit 652e125

Browse files
committed
Generate EXTENDED_JSON label in pipelines
If `JSON` is present in the actual string content, using `<<< JSON` as the multiline string label is considered unsafe and rector will scream about it (`SensitiveHereNowDocRector`) Seeing as `EXTENDED_JSON` is not and probably will never be present in the strings, use that for the heredoc/nowdoc to circumvent `SensitiveHereNowDocRector`
1 parent 1c53323 commit 652e125

7 files changed

Lines changed: 1267 additions & 1262 deletions

File tree

generator/src/OperatorTestGenerator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
127127

128128
$json = Document::fromPHP($filterAndUpdate)->toCanonicalExtendedJSON();
129129
$json = json_encode(json_decode($json), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
130-
$case = $dataEnum->addCase($caseName, new Literal('<<<\'JSON\'' . "\n" . $json . "\n" . 'JSON'));
130+
$case = $dataEnum->addCase($caseName, $this->jsonLiteral($json));
131131
$case->setComment($test->name);
132132
if ($test->link) {
133133
$case->addComment('');
@@ -159,7 +159,7 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
159159
$json = Document::fromPHP(['pipeline' => $pipeline])->toCanonicalExtendedJSON();
160160
// Unwrap the pipeline array and reformat for prettier JSON
161161
$json = json_encode(json_decode($json)->pipeline, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
162-
$case = $dataEnum->addCase($caseName, new Literal('<<<\'JSON\'' . "\n" . $json . "\n" . 'JSON'));
162+
$case = $dataEnum->addCase($caseName, $this->jsonLiteral($json));
163163
$case->setComment($test->name);
164164
if ($test->link) {
165165
$case->addComment('');
@@ -191,6 +191,11 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
191191
return $namespace;
192192
}
193193

194+
private function jsonLiteral(string $json): Literal
195+
{
196+
return new Literal('<<<\'EXTENDED_JSON\'' . "\n" . $json . "\n" . 'EXTENDED_JSON');
197+
}
198+
194199
private function convertYamlTaggedValues(mixed $object): mixed
195200
{
196201
if ($object instanceof TaggedValue) {

0 commit comments

Comments
 (0)