Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When setting config unknownTagsConverter to "bypass" an exception is thrown when converting #16

Closed
ahughes02 opened this issue Jan 3, 2018 · 6 comments
Labels
Milestone

Comments

@ahughes02
Copy link

ahughes02 commented Jan 3, 2018

Exception Message: An item with the same key has already been added.
Stacktrace:

   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at ReverseMarkdown.Converters.ByPass..ctor(Converter converter)
   at ReverseMarkdown.Converter.GetDefaultConverter(String tagName)
   at ReverseMarkdown.Converters.ConverterBase.TreatChildren(HtmlNode node)
   at ReverseMarkdown.Converters.Div.Convert(HtmlNode node)
   at ReverseMarkdown.Converters.ConverterBase.TreatChildren(HtmlNode node)
   at ReverseMarkdown.Converters.Div.Convert(HtmlNode node)
   at ReverseMarkdown.Converters.ConverterBase.TreatChildren(HtmlNode node)
   at ReverseMarkdown.Converters.Div.Convert(HtmlNode node)
   at ReverseMarkdown.Converters.ConverterBase.TreatChildren(HtmlNode node)
   at ReverseMarkdown.Converters.Div.Convert(HtmlNode node)
   at ReverseMarkdown.Converters.ConverterBase.TreatChildren(HtmlNode node)
   at ReverseMarkdown.Converters.Div.Convert(HtmlNode node)
   at ReverseMarkdown.Converters.ConverterBase.TreatChildren(HtmlNode node)
   at ReverseMarkdown.Converters.ByPass.Convert(HtmlNode node)
   at ReverseMarkdown.Converter.Convert(String html)
@ahughes02
Copy link
Author

I was able to resolve this by adding _converters.Remove(tagName); just before _converters.Add(tagName, converter); in the Converter.cs Register method. Not sure if that is the correct fix but it worked for my project.

@mysticmind
Copy link
Owner

mysticmind commented Jan 4, 2018

@ahughes02 definitely looks like a bug, could you please provide a repro use case (including sample html) to reproduce the issue?

Also did you register your own converter by any chance?

@ahughes02
Copy link
Author

Here is some sample HTML that causes the bug https://pastebin.com/raw/0nG6582p
This is the code I am running, except I am loading the HTML from a file. Pasting it inline works to demonstrate the bug though. I am not registering my own converter.

var converter = new ReverseMarkdown.Converter(config);
var html = "html goes here";
var temp = converter.Convert(html);

@mysticmind
Copy link
Owner

mysticmind commented Jan 4, 2018

@ahughes02 I figured out the issue, will fix and make available a new version later today.

@ahughes02
Copy link
Author

@mysticmind thanks for the quick response! This library works really great for our application and I really appreciate you making this available for everyone

mysticmind added a commit that referenced this issue Jan 4, 2018
- Fix bug GH-16 pertaining to unknown tags bypass option throwing an exception
- Add logic to validate Unknown tags option and throw an exception if
  invalid
- Add logic to throw an UnknownTagException rather than generic Exception
- Add units tests for different unknown tag options
@mysticmind mysticmind added the bug label Jan 4, 2018
@mysticmind mysticmind added this to the 1.5.0 milestone Jan 4, 2018
@mysticmind
Copy link
Owner

v1.5 published in Nuget which includes a fix for this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants