Does Foundation.URL.query(percentEncoded:) calls Foundation.URL.host(percentEncoded:) under the hood?

The context is that I am calling URL.query(percentEncoded:) to retrieve the query from a url. It works well on iOS 17 but somehow, on iOS 16, it triggers an EXC_BREAKPOINT crash when the query of the url is nil. It’s a known issue.

The weird thing I observe through the crash is that, xcode shows that the program is crashing on accessing the host, but I am accessing the query (I am not even using Foundation.URL.host(percentEncoded:) anywhere in my code). I don’t understand that why would accessing the query would also access the host?

It’s unusual that calling URL.query(percentEncoded:) would access the URL.host(percentEncoded:) internally, as they are typically separate components of a URL. However, it’s possible that under certain conditions, such as when the query is nil, the underlying implementation might check other parts of the URL, which could include the host.

I hope my suggestion will be helpful for everyone.

1 Like