Accessing .host on a URI without a host gives a 4005 error code

NEW
Unassigned

Status

()

Firefox
File Handling
5 years ago
2 years ago

People

(Reporter: mkaply, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

5 years ago
If you have a URL like about:blank as an nsIURI and try to access .host, it will error out with 0x80004005.

It shouldn't error, host should simply be null.

It makes it quite difficult to check if a URI has a host, because the moment you access it, it throws.

Comment 1

5 years ago
More importantly, you normally don't test URLs like about:blank and thus don't realize that you have a bug here.

If the API gives an nsIURI, it should adhere to the API and none of the attributes should throw. Same applies to all other attributes, not just |host|.

Actually, null is already a gotcha for developers, e.g. if you write uri.host.substr(-11) == ".google.com", it would still throw, so maybe "" is better. But "" is harder for C++ to check against. I guess null would be a compromise, because having to make a try/catch around each uri access is very painful, a null check is much easier.

Updated

2 years ago
Component: File Handling → File Handling
Product: Core → Firefox
Version: Trunk → unspecified
You need to log in before you can comment on or make changes to this bug.