addressable icon indicating copy to clipboard operation
addressable copied to clipboard

Add public_suffix method to allow users to access the PublicSuffix::Domain object easily.

Open excid3 opened this issue 2 years ago • 8 comments

This exposes the PublicSuffix::Domain object so users can interact with that as needed. Plus it provides a consistent interface for Addressable::URI to interact with.

This is useful for accessing subdomains. PublicSuffix's #trd method returns "www.test" from "www.test.example.org".

I'd also like to add subdomain & subdomains methods to Addressable::URI for direct access to subdomains (which I have a follow up Pull Request for if this is accepted).

excid3 avatar May 10 '23 14:05 excid3

This exposes the PublicSuffix::Domain object

a bit hesitant about this, sure this object looks simple enough now, but what if it changes down the road? There could be unexpected breaking changes for users of addressable then

dentarg avatar May 11 '23 12:05 dentarg

Addressable already relies on it, so it would need to be updated for breaking changes as well. It also seems pretty unlikely to change since it only handles parsing domains.

I've been working with a lot of apps that allow custom domains & subdomains and it would be really helpful for Addressable to support parsing those out. I was surprised that wasn't a feature considering it was already using PublicSuffix.

I can merge the subdomain & subdomains feature into this branch if you'd prefer to consider it all together.

excid3 avatar May 11 '23 13:05 excid3

Decided to merge the subdomain methods into this PR to show the complete feature.

excid3 avatar May 11 '23 13:05 excid3

Addressable already relies on it, so it would need to be updated for breaking changes as well.

Yes, but we own the API, and I think it is a difference in interacting with PublicSuffix to get a basic value (e.g. String) then returning a full PublicSuffix object.

It also seems pretty unlikely to change since it only handles parsing domains.

Yeah, PublicSuffix::Domain probably wont change but let's not take any chances.

dentarg avatar May 11 '23 20:05 dentarg

What do you think works best? Should we keep the subdomain and subdomains methods and make public_suffix private?

excid3 avatar May 11 '23 20:05 excid3

I'm not sold on these additions. I'm feel there's ambiguity around the terms "subdomain" and "subdomains"... this looks a bit different from what publicsuffix-ruby does?

irb(main):006:0> PublicSuffix.parse("www.google.com", ignore_private: true).subdomain
=> "www.google.com"

dentarg avatar May 11 '23 20:05 dentarg

I'm not sold on these additions. I'm feel there's ambiguity around the terms "subdomain" and "subdomains"... this looks a bit different from what publicsuffix-ruby does?

That was on purpose. I wanted a way to access the subdomains (without the primary domain).

The subdomain method from PublicSuffix doesn't really add any value since it's basically the same as host in Addressable.

excid3 avatar May 11 '23 21:05 excid3

@sporkmonger any thoughts on this?

dentarg avatar Jun 03 '23 20:06 dentarg