Skip to content

[5.x]: Phone link value formats with + #16300

@MangoMarcus

Description

@MangoMarcus

What happened?

Description

Not 100% sure this is a bug but it does seem to be unintended behaviour - Craft formats phone number values by replacing the spaces with +. Eg. +1 234 567 is formatted as +1+234+567.

The + character already denotes the international exit code in a phone number, I'm not sure if it's actually invalid though or if that only applies to the first +.

I think this is unintended anyway though because craft\fields\linktype\Phone::normalizeValue() contains $value = str_replace(' ', '-', $value), but that method seems to only be called by craft\fields\Link::normalizeValue() which uses str_replace(' ', '+', $value) first - meaning that $value will never contain spaces in craft\fields\linktype\Phone::normalizeValue() and so $value = str_replace(' ', '-', $value) is redundant.

I thought %20 was a valid representation for spaces in tel URIs but glancing through the spec it seems hyphens are preferred, so I'm guessing this is an oversight?

Steps to reproduce

  1. Create a link field with phone number as the only link type, and add it to an entry type
  2. Paste a number with spaces into the phone numbers value field eg +1 234 567 and save

Expected behavior

Craft either

  1. Formats the value by removing spaces
  2. Formats the value by replacing the spaces with hyphens
  3. Saves the content as-is with the spaces and encodes later eg. when using getLink() (this is Hyper's approach)

Actual behavior

Craft formats the value as +1+234+567

Craft CMS version

5.5.4

PHP version

8.3.8

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions