Skip to content

[5.x]: Breaking change in UrlHelper::isAbsoluteUrl() #15043

@khalwat

Description

@khalwat

What happened?

Description

It appears that this change is a breaking change in UrlHelper::isAbsoluteUrl()

In Craft 3/4, the following code:

        Craft::dd(UrlHelper::isAbsoluteUrl('C:\Users\joshcrawford\public_html\formie-craft5\vendor\verbb\formie\src\web\assets\forms\dist\manifest.json'));

...properly returns false

However on Craft 5 after the above change to UrlHelper::isAbsoluteUrl():

        Craft::dd(UrlHelper::isAbsoluteUrl('C:\Users\joshcrawford\public_html\formie-craft5\vendor\verbb\formie\src\web\assets\forms\dist\manifest.json'));

...returns true

Which I think is likely objectively wrong?

Yes, I know it's a file path that we're passing in, but in my case the param could be a URL or it could be a path, and I'm using UrlHelper::isAbsoluteUrl() to determine whether it's a fully qualified absolute URL, and if not, we assume it's a file path by the time we get there.

The change was made to fix #14830 but perhaps special-casing for mailto: or rejecting anything that begins with a capital letter and a colon would be less behavior braking?

I realize that arguably I should be testing to see whether it is a URL at all before passing it in to UrlHelper::isAbsoluteUrl() but I looked at the code for that function at the time, and figured it'd be as good of a way as any to determine whether it's a URL or path.

Even if I should not be using UrlHelper::isAbsoluteUrl() with a path to determine if it's an absolute URL, I'm not sure the current behavior should break?

Related issue: nystudio107/craft-plugin-vite#25

Steps to reproduce

  1. Try using UrlHelper::isAbsoluteUrl() with a Window file path such as:
'C:\Users\joshcrawford\public_html\formie-craft5\vendor\verbb\formie\src\web\assets\forms\dist\manifest.json'

Expected behavior

It would return false for a Windows file system path

Actual behavior

It returns true

Craft CMS version

Craft 5

PHP version

n/a

Operating system and version

n/a

Database type and version

n/a

Image driver and version

n/a

Installed plugins and versions

  • Vite plugin
  • Any plugin that depends on craft-plugin-vite such as Formie, SEOmatic, Retour, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions