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
- Create a link field with phone number as the only link type, and add it to an entry type
- Paste a number with spaces into the phone numbers value field eg
+1 234 567 and save
Expected behavior
Craft either
- Formats the value by removing spaces
- Formats the value by replacing the spaces with hyphens
- 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
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 567is 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 bycraft\fields\Link::normalizeValue()which usesstr_replace(' ', '+', $value)first - meaning that$valuewill never contain spaces incraft\fields\linktype\Phone::normalizeValue()and so$value = str_replace(' ', '-', $value)is redundant.I thought
%20was 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 234 567and saveExpected behavior
Craft either
getLink()(this is Hyper's approach)Actual behavior
Craft formats the value as
+1+234+567Craft 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