Base_url_no_prefix actually base_url_no_suffix?


(Leo McArdle) #1

Noticed this while cleaning up my CSP proof of concept:

Discourse.base_url_no_prefix seems to actually be the base url sans path (not protocol, as I would expect), compare base_url_no_prefix to base_url below:

So, I propose base_url_no_prefix is renamed base_url_no_suffix or base_url_no_path to clear up any future confusion.


(Jeff Atwood) #2

Sure what do you think @neil? Naming is important!


(Neil Lalonde) #3

But it’s a prefix to all paths. A path suffix would be strange. I don’t agree that this name is confusing.


(Stephen) #4

Seems fine as-is. It’s the base URL without a prefix. Saying no suffix on a base URL is redundant.
As to no path, that’s just confusing- it’s valid without a path, right?


(Leo McArdle) #5

But surely the method would have to be named base_url_no_path_prefix to be able to extract that meaning from it. With no mention of any path, there’s no reason to assume prefix refers to anything other than the base url’s prefix.

Don’t want to labour the point here (though after proofreading I realized I have), but suppose discourse were running from https://example.com/discourse:

Currently, the methods would produce the following:

base_uri: /discourse
base_protocol: https
base_url_no_prefix: https://example.com
base_url: https://example.com/discourse

Whereas if I were to take a guess at what they would produce without having read the source:

base_uri: ??? could be many many different things
base_protocol: https
base_url_no_prefix: example.com/discourse
base_url: https://example.com/discourse

I humbly propose those methods are renamed like so:

base_uribase_path
base_protocol
base_url_no_prefixbase_url_no_path (let’s remove any confusion over what prefix/suffix is referring to)
base_url

But maybe my brain works a bit differently, I don’t mind that much - certainly less than the length of this post suggests :slight_smile: