Skip to content

Commit

Permalink
fixes #21 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r authored and joemcbride committed Mar 20, 2019
1 parent de9ffa2 commit aa3d963
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/GraphQLParser.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using GraphQLParser;
using GraphQLParser.AST;
using GraphQLParser.Exceptions;
using System;
using System.Linq;
using Xunit;
Expand All @@ -10,6 +11,13 @@ public class ParserTests
{
private static readonly string NL = Environment.NewLine;

[Fact]
public void Parse_Unicode_Char_At_EOF_Should_Throw()
{
var parser = new Parser(new Lexer());
Assert.Throws<GraphQLSyntaxErrorException>(() => parser.Parse(new Source("{\"\\ue }")));
}

[Fact]
public void Parse_FieldInput_HasCorrectEndLocationAttribute()
{
Expand Down
8 changes: 7 additions & 1 deletion src/GraphQLParser/LexerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,14 @@ private int GetPositionAfterWhitespace(string body, int start)

private char GetUnicodeChar()
{
var expression = this.source.Body.Substring(this.currentIndex, 5);
if (this.currentIndex + 5 > this.source.Body.Length)
{
var truncatedExpression = this.source.Body.Substring(this.currentIndex);
throw new GraphQLSyntaxErrorException($"Invalid character escape sequence at EOF: \\{truncatedExpression}.", this.source, this.currentIndex);
}

var expression = this.source.Body.Substring(this.currentIndex, 5);

if (!this.OnlyHexInString(expression.Substring(1)))
{
throw new GraphQLSyntaxErrorException($"Invalid character escape sequence: \\{expression}.", this.source, this.currentIndex);
Expand Down

0 comments on commit aa3d963

Please sign in to comment.