Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Potential small bug in Tokenizer.Lookahead when using TakeAll(...) #527

@Antaris

Description

@Antaris

I'm currently working on an experimental port of the Razor parser to typescript, and on reviewing the tokenizer code, I've noticed what I perceive to be a small error when performing a lookahead.

https://github.com/aspnet/Razor/blob/dev/src/Microsoft.AspNet.Razor/Tokenizer/Tokenizer.cs#L288

The Tokenizer.Lookahead method allows you to perform a lookahead operation on the input text document. This is called through either Tokenizer.TakeAll and Tokenizer.At, but its the TakeAll method that passes the takeIfMatch parameter set to true which preserves the existing buffer content while attempting the operation, but I've noticed that you're not actually storing the buffer content. See the following:

// Capture the current buffer content in case we have to backtrack
string oldBuffer = null;
if (takeIfMatch)
{
  Buffer.ToString();
}

Later you're then trying to restore the content to the buffer:

https://github.com/aspnet/Razor/blob/dev/src/Microsoft.AspNet.Razor/Tokenizer/Tokenizer.cs#L301

if (takeIfMatch)
{
  // Clear the buffer and put the old buffer text back
  Buffer.Clear();
  Buffer.Append(oldBuffer);
}

At this stage, oldBuffer is never assigned, so nothing would be restored to the buffer.

Is this intentional or just an err? Happy to do a PR to correct it if its an issue, but having been in there for quite a while, I'm guessing it's likely not an issue?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions