Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions modules/core/src/main/scala/parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,13 @@ object GraphQLParser {

/**
* Parser that consumes a comment
*
* A comment ends at a line terminator or at the end of the file.
*/
val comment: Parser[Unit] =
(char('#') *> charWhere(c => c != '\n' && c != '\r').rep0 <* charIn(
(char('#') *> charWhere(c => c != '\n' && c != '\r').rep0 <* (charIn(
'\n',
'\r') <* skipWhitespace).void
'\r').void | Parser.end) <* skipWhitespace).void

/**
* Turns a parser into one that skips trailing whitespace and comments
Expand Down
9 changes: 9 additions & 0 deletions modules/core/src/test/scala/parser/ParserSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,15 @@ final class ParserSuite extends CatsEffectSuite {
assertEquals(resFail, Result.failure(expectedFail))
}

test("comment at end of file without a line terminator") {
val expected =
List(Operation(Query, None, Nil, Nil, List(Field(None, Name("x"), Nil, Nil, Nil))))

assertEquals(parser.parseText("query { x } # done"), Result(expected))
assertEquals(parser.parseText("query { x } #"), Result(expected))
assertEquals(parser.parseText("query { # inner\n x } # a\n# b"), Result(expected))
}

def mkParser(
maxSelectionDepth: Int = GraphQLParser.defaultConfig.maxSelectionDepth,
maxSelectionWidth: Int = GraphQLParser.defaultConfig.maxSelectionWidth,
Expand Down
Loading