Skip to content

Commit d2b9f9c

Browse files
authored
Do not escape forward slashes in Printer
1 parent c7f84dd commit d2b9f9c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Language/Printer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ protected function p(?Node $node): string
414414
return BlockString::print($node->value);
415415
}
416416

417-
return json_encode($node->value, JSON_THROW_ON_ERROR);
417+
return json_encode($node->value, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
418418

419419
case $node instanceof UnionTypeDefinitionNode:
420420
$typesStr = $this->printList($node->types, ' | ');

tests/Language/PrinterTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,29 @@ public function testPrintPrimitives(): void
291291
self::assertASTMatches('3', AST::astFromValue(3, Type::int()));
292292
self::assertASTMatches('3.14', AST::astFromValue(3.14, Type::float()));
293293
}
294+
295+
public function testDoNotEscapeForwardSlash(): void
296+
{
297+
$ast = Parser::parse(
298+
<<<'GRAPHQL'
299+
query {
300+
search(query: "repo: webonyx/graphql-php") {
301+
id
302+
}
303+
}
304+
GRAPHQL
305+
);
306+
307+
self::assertSame(
308+
<<<'GRAPHQL'
309+
{
310+
search(query: "repo: webonyx/graphql-php") {
311+
id
312+
}
313+
}
314+
315+
GRAPHQL,
316+
Printer::doPrint($ast),
317+
);
318+
}
294319
}

0 commit comments

Comments
 (0)