From 797bf9ad4f935fe069b8d9c7096210ff77371c28 Mon Sep 17 00:00:00 2001 From: sh1l0n Date: Wed, 3 Apr 2024 11:20:48 +0200 Subject: [PATCH 1/3] Fixed visitStringValueNode for string blocks --- gql/lib/src/language/printer.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gql/lib/src/language/printer.dart b/gql/lib/src/language/printer.dart index 9f2530d47..e8638f177 100644 --- a/gql/lib/src/language/printer.dart +++ b/gql/lib/src/language/printer.dart @@ -184,7 +184,10 @@ class _PrintVisitor extends Visitor { '"""', "\n", _indent(_tabs), - stringValueNode.value.replaceAll('"""', '\\"""'), + stringValueNode.value + .replaceAll('"""', '\\"""') + .replaceAll('\\', '\\\\') + .replaceAll('\n', '\\n'), "\n", _indent(_tabs), '"""', From ddf36102d0b4590ed0dd35859b3c2f2fcc9bf65a Mon Sep 17 00:00:00 2001 From: sh1l0n Date: Wed, 3 Apr 2024 11:37:29 +0200 Subject: [PATCH 2/3] format string even with is not a block --- gql/lib/src/language/printer.dart | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gql/lib/src/language/printer.dart b/gql/lib/src/language/printer.dart index e8638f177..d357bd207 100644 --- a/gql/lib/src/language/printer.dart +++ b/gql/lib/src/language/printer.dart @@ -172,10 +172,14 @@ class _PrintVisitor extends Visitor { @override String visitStringValueNode(StringValueNode stringValueNode) { + final formattedString = stringValueNode.value + .replaceAll('"""', '\\"""') + .replaceAll('\\', '\\\\') + .replaceAll('\n', '\\n'); if (!stringValueNode.isBlock) { return [ '"', - stringValueNode.value, + formattedString, '"', ].join(); } @@ -184,10 +188,7 @@ class _PrintVisitor extends Visitor { '"""', "\n", _indent(_tabs), - stringValueNode.value - .replaceAll('"""', '\\"""') - .replaceAll('\\', '\\\\') - .replaceAll('\n', '\\n'), + formattedString, "\n", _indent(_tabs), '"""', From ae3d44c58f2d146cd6252438ad0cffea288c0a6d Mon Sep 17 00:00:00 2001 From: sh1l0n Date: Fri, 5 Apr 2024 00:58:15 +0200 Subject: [PATCH 3/3] Align with https://spec.graphql.org/June2018/#sec-String-Value --- gql/lib/src/language/printer.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gql/lib/src/language/printer.dart b/gql/lib/src/language/printer.dart index d357bd207..30a877e49 100644 --- a/gql/lib/src/language/printer.dart +++ b/gql/lib/src/language/printer.dart @@ -174,8 +174,14 @@ class _PrintVisitor extends Visitor { String visitStringValueNode(StringValueNode stringValueNode) { final formattedString = stringValueNode.value .replaceAll('"""', '\\"""') + .replaceAll('\"', '\\"') + .replaceAll('\/', '\\/') .replaceAll('\\', '\\\\') - .replaceAll('\n', '\\n'); + .replaceAll('\b', '\\b') + .replaceAll('\f', '\\f') + .replaceAll('\n', '\\n') + .replaceAll('\r', '\\r') + .replaceAll('\t', '\\t'); if (!stringValueNode.isBlock) { return [ '"',