Skip to content

Improve parse_url usage #254

@gRegorLove

Description

@gRegorLove

In some edge cases, I’ve gotten a TypeError in parseUriToComponents(), when called by the function resolveUrl() (not the class method of the same name). This happens because parse_url can return false and it’s not checking for that before calling array_key_exists:

array_key_exists(): Argument #2 ($array) must be of type array, bool given

A real-world example is @pmoralesgarcia has domain-relative links like href="/blog/tag:2024/" which parse_url has trouble with, probably because of the colon. I haven’t researched the best solution, but something like the class method might be enough. It might be worth seeing what sabre-io/uri does. I’ve been using that in some other code and liking it so far.

(Originally published at: https://gregorlove.com/2024/03/improve-parse-url-usage/)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions