Skip to content

Commit

Permalink
Fix hanging on incomplete directives. #638
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-ra committed Jul 13, 2022
1 parent 43a17b9 commit 898dea8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion YamlDotNet/Core/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ private void FetchDirective()

default:
// warning: skipping reserved directive line
while (!analyzer.Check('#') && !analyzer.IsBreak())
while (!analyzer.EndOfInput && !analyzer.Check('#') && !analyzer.IsBreak())
{
Skip();
}
Expand Down Expand Up @@ -2284,6 +2284,13 @@ private string ScanDirectiveName(in Mark start)
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a directive, could not find expected directive name.");
}

// Check for end of stream

if (analyzer.EndOfInput)
{
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a directive, found unexpected end of stream.");
}

// Check for an blank character after the name.

if (!analyzer.IsWhiteBreakOrZero())
Expand Down

0 comments on commit 898dea8

Please sign in to comment.