Skip to content

Parse() can throw unexpected exceptions #766

Open
@mschessler

Description

@mschessler

Describe the bug
Is parse() supposed to be able to deal with user input ? Currently it throws several unexpected exceptions on malformed input. I would expect xFunc.Maths.ParseException or xFunc.Maths.TokenizeException.

First Case
var exp = processor.Parse("2e");

System.FormatException: The input string '2e' was not in a correct format.
at System.Number.ThrowFormatException[TChar](ReadOnlySpan1 value) at System.Double.Parse(ReadOnlySpan1 s, IFormatProvider provider)
at xFunc.Maths.Tokenization.Lexer.CreateDecToken()
at xFunc.Maths.Tokenization.Lexer.CreateNumberToken()
at xFunc.Maths.Tokenization.Lexer.MoveNext()
at xFunc.Maths.Parser.TokenReader.Read()
at xFunc.Maths.Parser.TokenReader.GetCurrentAndAdvance(TokenKind kind)
at xFunc.Maths.Parser.ParseFor(TokenReader& tokenReader)
at xFunc.Maths.Parser.ParseStatement(TokenReader& tokenReader)
at xFunc.Maths.Parser.Parse(String expression)
at xFunc.Maths.Processor.Parse(String function)

Second Case
var exp = processor.Parse("0111111111111151111110000");

System.OverflowException: Arithmetic operation resulted in an overflow.
at xFunc.Maths.Tokenization.ParseNumbers.GrabLongs(Int32 radix, ReadOnlySpan1 s, Int32& i) at xFunc.Maths.Tokenization.ParseNumbers.ToInt64(ReadOnlySpan1 value, Int32 fromBase)
at xFunc.Maths.Tokenization.Lexer.CreateOctToken()
at xFunc.Maths.Tokenization.Lexer.CreateNumberToken()
at xFunc.Maths.Tokenization.Lexer.MoveNext()
at xFunc.Maths.Parser.TokenReader.Read()
at xFunc.Maths.Parser.TokenReader.GetCurrentAndAdvance(TokenKind kind)
at xFunc.Maths.Parser.ParseFor(TokenReader& tokenReader)
at xFunc.Maths.Parser.ParseStatement(TokenReader& tokenReader)
at xFunc.Maths.Parser.Parse(String expression)
at xFunc.Maths.Processor.Parse(String function)

Third Case
string = "{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{"

Trying to parse it leads to a StackOverflow.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions