Update URL parsing logic (again). #1996
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This improves upon a fix I submitted earlier regarding the
FlxStringUtil.getDomain()
function, addressing some concerns I brought up to @Gama11. I wanted to submit this work now for greater visibility and general review, even though this is a fairly low priority item.The main item is the introduction of a new public function,
FlxStringUtil.getHost()
, which takes care of proper URL parsing in a more robust manner. It supports nearly all of RFC 3986, with the only notable exception being the "IPvFuture" extension to IPv6. (I could not find any practical examples of the extension to use for testing, so I opted to omit it from the regex.) This moves the URL parsing logic out of the existinggetDomain()
function, which now focuses only on extracting the first- and second-level domains from a host.Breaking change: The
getDomain()
function used to return"local"
upon failure. This was undocumented behavior carried over from when it was it part of theFlxBasePreloader
class. This PR changes the failure value to the empty string (""
), which just feels like a better design for a public API. The necessary changes have been made toFlxBasePreloader
, cleaning up its logic in the process.Finally, the unit tests I introduced for
getDomain()
have been expanded upon to testgetHost()
as well.