nager / Nager.PublicSuffix

.NET public suffix domain parser
MIT License
153 stars 21 forks source link

Add provider combinator #54

Closed merijndejonge closed 2 years ago

merijndejonge commented 2 years ago

Hello, I created a pull request with a few minor improvements:

I hope you like these enhancements and that you will merge them into a new version of your nice library.

Happy coding! Merijn

tinohager commented 2 years ago

Thanks for the pull request, currently I don't want to transfer the logic to the main project because this is a very special case.

merijndejonge commented 2 years ago

Let me explain a bit further then:

  1. I believe that the equality checking for TldRule is a general improvement that enables rules to be compared based on their name rather than on their physical objects. If you prefer, I can create a separate pull request for this.
  2. The StringTldRuleProvider is good for testing because it enables tests without external dependencies on the remote tld provider and/or local files with rules.
  3. I created the rule combinator for the not so very-specific case that a software system needs rules that are not yet available in the official public suffix list, rules that are not allowed to be added, or rules that are not intended for inclusion in the public list. Without the combinator, the only option I see is to duplicate the online public suffix list in a file. Add local rules to the file and use FileTldRuleProvider to access them. This, however, introduces a maintenance issue, because how to keep my local file in sync with the online list? With the combinator this is easy. I can put just my specific rules in the local file and use FileTldRuleProvider to access them. I combine these with the up-to-date online list using WebTldRuleProvider and TldRuleProviderCombinator.

If this doesn’t convince you, I can implement TldRuleProviderCombinator in my own codebase, of course. For that, I would still need, the equality checking functionality. So perhaps, could you consider at least accepting 1 (equality) and 2 (StringTldRuleProvider)?

If you need more info, just let me know!

wouter-b commented 2 years ago

This very special case is exactly my case. I want to combine the global suffix list with a small string list of my own. Par example for myname.onmicrosoft.com I want the domain to be myname. I could easily use an if else statement, but this would make it so much cleaner.

merijndejonge commented 2 years ago

Hi @tinohager, Could you please respond to my explanation? Now that @wouter-b also asks for this functionality, my request becomes less special, I wold say ;-)

tinohager commented 2 years ago

@merijndejonge I will be in touch during the week I am currently sick

tinohager commented 2 years ago

Hi, i have add the TldRule compare logic. Now it should work to implement your extension as an add-on without touching the base

merijndejonge commented 2 years ago

Thank you very much!