Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into 0.3.0-ALPHA
Browse files Browse the repository at this point in the history
  • Loading branch information
pgutkowski committed Oct 20, 2018
2 parents e2b0c69 + 6237ff4 commit 01202f8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jacoco {
}

task sourceJar(type: Jar) {
from sourceSets.main.allJava
from sourceSets.main.allSource
}

jacocoTestReport {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ fun tokenizeRequest(input : String) : List<String> {
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\"")
}
Expand All @@ -41,6 +42,29 @@ fun tokenizeRequest(input : String) : List<String> {
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<String>) : Document {
val operations : MutableList<Document.OperationTokens> = mutableListOf()
val fragments : MutableList<Document.FragmentTokens> = mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ class RequestTokenizationTest {
)
)
}

@Test
fun `tokenize input with quotes`(){
testTokenization(
input = "{hello(name : \"Ted\\\" Mosby\")}",
expected = listOf("{", "hello", "(", "name", ":", "\"Ted\\\" Mosby\"", ")", "}")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>("data/String"), equalTo(input))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SchemaException>("Illegal name '__field'. Names starting with '__' are reserved for introspection system"){
KGraphQL.schema { query("underscore"){ resolver { -> Underscore(0) } } }
}
Expand Down Expand Up @@ -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<SchemaException>("Illegal name '__id'. Names starting with '__' are reserved for introspection system"){
KGraphQL.schema {
query("many") { resolver { __id : String -> ManyFields(__id) } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SchemaException>("Type name starting with \"__\" are excluded for introspection system"){
schema {
type<__Type>()
Expand Down

0 comments on commit 01202f8

Please sign in to comment.