From a83e9e11ce17fa96bf28aea97aee2aba513e3ef3 Mon Sep 17 00:00:00 2001 From: Pawel Gutkowski Date: Fri, 28 Sep 2018 09:51:37 +0200 Subject: [PATCH 1/4] Fix issue #24 : handle quote escaping --- .../kgraphql/request/RequestPreProcessing.kt | 26 ++++++++++++++++++- .../request/RequestTokenizationTest.kt | 8 ++++++ .../language/InputValuesSpecificationTest.kt | 2 +- .../typesystem/ObjectsSpecificationTest.kt | 4 +-- .../typesystem/TypeSystemSpecificationTest.kt | 2 +- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/github/pgutkowski/kgraphql/request/RequestPreProcessing.kt b/src/main/kotlin/com/github/pgutkowski/kgraphql/request/RequestPreProcessing.kt index 621cc576..6cf135c2 100644 --- a/src/main/kotlin/com/github/pgutkowski/kgraphql/request/RequestPreProcessing.kt +++ b/src/main/kotlin/com/github/pgutkowski/kgraphql/request/RequestPreProcessing.kt @@ -21,7 +21,8 @@ fun tokenizeRequest(input : String) : List { i++ } '\"' -> { - val token = input.substring(i+1).takeWhile { it != '\"' } + val substring = input.substring(i + 1) + val token = extractValueToken(substring) i += token.length + 2 //2 for quotes tokens.add("\"$token\"") } @@ -41,6 +42,29 @@ fun tokenizeRequest(input : String) : List { return tokens } +private fun extractValueToken(substring: String): String { + var index = 0 + var isEscaped = false + + val tokenBuilder = StringBuilder() + + loop@ while (index < substring.length) { + val currentChar = substring[index] + + isEscaped = when { + currentChar == '\"' && isEscaped.not() -> break@loop + currentChar == '\\' -> true + else -> false + } + + tokenBuilder.append(currentChar) + + index++ + } + + return tokenBuilder.toString() +} + fun createDocumentTokens(tokens : List) : Document { val operations : MutableList = mutableListOf() val fragments : MutableList = mutableListOf() diff --git a/src/test/kotlin/com/github/pgutkowski/kgraphql/request/RequestTokenizationTest.kt b/src/test/kotlin/com/github/pgutkowski/kgraphql/request/RequestTokenizationTest.kt index b080e251..fd8063fc 100644 --- a/src/test/kotlin/com/github/pgutkowski/kgraphql/request/RequestTokenizationTest.kt +++ b/src/test/kotlin/com/github/pgutkowski/kgraphql/request/RequestTokenizationTest.kt @@ -50,4 +50,12 @@ class RequestTokenizationTest { ) ) } + + @Test + fun `tokenize input with quotes`(){ + testTokenization( + input = "{hello(name : \"Ted\\\" Mosby\")}", + expected = listOf("{", "hello", "(", "name", ":", "\"Ted\\\" Mosby\"", ")", "}") + ) + } } \ No newline at end of file diff --git a/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/language/InputValuesSpecificationTest.kt b/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/language/InputValuesSpecificationTest.kt index ad010e66..5e5b21d1 100644 --- a/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/language/InputValuesSpecificationTest.kt +++ b/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/language/InputValuesSpecificationTest.kt @@ -72,7 +72,7 @@ class InputValuesSpecificationTest { @Test @Specification("2.9.4 String Value") fun `String input value`(){ - val input = "\\Ala ma kota \\\n\\kot ma Alę\\" + val input = "\\Ala ma kota \\\n\\kot ma Alę" val response = deserialize(schema.execute("{String(value : \"$input\")}")) assertThat(response.extract("data/String"), equalTo(input)) } diff --git a/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/typesystem/ObjectsSpecificationTest.kt b/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/typesystem/ObjectsSpecificationTest.kt index 2881f4b6..ff33c0c9 100644 --- a/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/typesystem/ObjectsSpecificationTest.kt +++ b/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/typesystem/ObjectsSpecificationTest.kt @@ -15,7 +15,7 @@ class ObjectsSpecificationTest { data class Underscore(val __field : Int) @Test - fun `All fields defined within an Object type must not have a name which begins with "__"`(){ + fun `All fields defined within an Object type must not have a name which begins with __`(){ expect("Illegal name '__field'. Names starting with '__' are reserved for introspection system"){ KGraphQL.schema { query("underscore"){ resolver { -> Underscore(0) } } } } @@ -123,7 +123,7 @@ class ObjectsSpecificationTest { } @Test - fun `All arguments defined within a field must not have a name which begins with "__"`(){ + fun `All arguments defined within a field must not have a name which begins with __`(){ expect("Illegal name '__id'. Names starting with '__' are reserved for introspection system"){ KGraphQL.schema { query("many") { resolver { __id : String -> ManyFields(__id) } } diff --git a/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/typesystem/TypeSystemSpecificationTest.kt b/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/typesystem/TypeSystemSpecificationTest.kt index af45d179..b9178e8b 100644 --- a/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/typesystem/TypeSystemSpecificationTest.kt +++ b/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/typesystem/TypeSystemSpecificationTest.kt @@ -23,7 +23,7 @@ class TypeSystemSpecificationTest { } @Test - fun `All types and directives defined within a schema must not have a name which begins with "__"`(){ + fun `All types and directives defined within a schema must not have a name which begins with __`(){ expect("Type name starting with \"__\" are excluded for introspection system"){ schema { type<__Type>() From 573898af55c0fec5a0698c8c0deec2ce049fe043 Mon Sep 17 00:00:00 2001 From: PawelGutkowski Date: Sun, 30 Sep 2018 17:20:01 +0200 Subject: [PATCH 2/4] Release 0.2.8 --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 2e2299a0..002b7605 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'com.github.pgutkowski' -version '0.2.7' +version '0.2.8' buildscript { ext.kotlin_version = '1.2.50' @@ -115,10 +115,10 @@ bintray { publications = ['MyPublication'] version { - name = '0.2.7' + name = '0.2.8' desc = 'KGraphQL alpha release' released = new Date() - vcsTag = '0.2.7' + vcsTag = '0.2.8' } } } From 58051f85beb1827f18ca201682438c86851187fb Mon Sep 17 00:00:00 2001 From: Rainer Schmitz Date: Wed, 17 Oct 2018 15:23:21 +0200 Subject: [PATCH 3/4] Include Kotlin source files in source jar. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 002b7605..2b8334e3 100644 --- a/build.gradle +++ b/build.gradle @@ -70,7 +70,7 @@ jacoco { } task sourceJar(type: Jar) { - from sourceSets.main.allJava + from sourceSets.main.allSource } jacocoTestReport { From 6237ff4bfe81123c93f47450d4a6518df4064392 Mon Sep 17 00:00:00 2001 From: PawelGutkowski Date: Sat, 20 Oct 2018 13:30:23 +0200 Subject: [PATCH 4/4] Release 0.2.9 --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 2b8334e3..14fa9f2a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'com.github.pgutkowski' -version '0.2.8' +version '0.2.9' buildscript { ext.kotlin_version = '1.2.50' @@ -115,10 +115,10 @@ bintray { publications = ['MyPublication'] version { - name = '0.2.8' + name = '0.2.9' desc = 'KGraphQL alpha release' released = new Date() - vcsTag = '0.2.8' + vcsTag = '0.2.9' } } }