AngleSharp / AngleSharp.Css

:angel: Library to enable support for cascading stylesheets in AngleSharp.
https://anglesharp.github.io
MIT License
72 stars 34 forks source link

FormatException in ColorParse #33

Closed ahazelwood closed 5 years ago

ahazelwood commented 5 years ago

Issue Templates

Please use one of the following templates to create your issue:

Getting the following exception information on parsing some html. No chance to recover exists because exception breaks parsing. Stack trace is:

System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(ReadOnlySpan`1 str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(ReadOnlySpan`1 s, NumberStyles style, NumberFormatInfo info)
   at AngleSharp.Css.Parser.ColorParser.ParseRgbComponent(StringSource source)
   at AngleSharp.Css.Parser.ColorParser.ParseRgba(StringSource source)
   at AngleSharp.Css.Parser.ColorParser.Start(StringSource source)
   at AngleSharp.Css.Parser.ColorParser.ParseColor(StringSource source)
   at AngleSharp.Css.Converters.StructValueConverter`1.Convert(StringSource source)
   at AngleSharp.Css.Converters.OrValueConverter.Convert(StringSource source)
   at AngleSharp.Css.Converters.ValueConverterExtensions.Convert(IValueConverter converter, String value)
   at AngleSharp.Css.Dom.CssProperty.set_Value(String value)
   at AngleSharp.Css.Dom.CssStyleDeclaration.SetProperty(String propertyName, String propertyValue, String priority)
   at AngleSharp.Css.Parser.CssBuilder.CreateDeclarationWith(ICssProperties properties, CssToken& token)
   at AngleSharp.Css.Parser.CssBuilder.FillDeclarations(CssStyleDeclaration style, CssToken token)
   at AngleSharp.Css.Parser.CssParser.Parse[T](String source, Func`3 create)
   at AngleSharp.Css.Dom.CssStyleDeclaration.Update(String value)
   at AngleSharp.Css.Dom.ElementCssInlineStyleExtensions.CreateStyle(IElement element, String source)
   at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValueLocked(TKey key, CreateValueCallback createValueCallback)
   at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key, CreateValueCallback createValueCallback)
   at AngleSharp.Css.StyleAttributeObserver.AngleSharp.Dom.IAttributeObserver.NotifyChange(IElement host, String name, String value)
   at AngleSharp.Dom.Element.SetupElement()
   at AngleSharp.Html.Parser.HtmlDomBuilder.CloseCurrentNode()
   at AngleSharp.Html.Parser.HtmlDomBuilder.InBodyEndTagAnythingElse(HtmlTagToken tag)
   at AngleSharp.Html.Parser.HtmlDomBuilder.InBodyEndTag(HtmlTagToken tag)
   at AngleSharp.Html.Parser.HtmlDomBuilder.Parse(HtmlParserOptions options)
   at AngleSharp.Html.Parser.HtmlParser.Parse(HtmlDocument document)
   at CI. <snipped>

Appears to be because of the numeric.Parse functions. At the very least the exceptions should be caught and null returned.

Thanks.

FlorianRappl commented 5 years ago

What is the input?

Please provide a MWE to reproduce and fix the issue. Thanks!

ahazelwood commented 5 years ago

It was some random web page (not sure which one) that I came across. In tracking it down, I did notice that no exceptions were being caught around the number parsing, so probably a good fix to implement. I’ll let you know if I come across it again.

From: Florian Rappl notifications@github.com Sent: Friday, May 24, 2019 1:25 PM To: AngleSharp/AngleSharp.Css AngleSharp.Css@noreply.github.com Cc: Andre' Hazelwood ahazelwood@ciradar.com; Author author@noreply.github.com Subject: Re: [AngleSharp/AngleSharp.Css] FormatException in ColorParse (#33)

What is the input?

Please provide an MWEhttps://en.wikipedia.org/wiki/Minimal_working_example. Thanks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/AngleSharp/AngleSharp.Css/issues/33?email_source=notifications&email_token=AACS73FMRH45BDY3UWYQ2XTPXAQHFA5CNFSM4HPRKTEKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWGBI2Y#issuecomment-495719531, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AACS73HUBSYKM4MSY2HHJCDPXAQHFANCNFSM4HPRKTEA.

FlorianRappl commented 5 years ago

Solved in devel.