Skip to content

[4.x]: Php Intl extension using \u202f character in pattern string, and causing some unexpected behavior. #13381

Closed

Description

What happened?

Description

This is a really weird one that took a couple days to figure out, and isn't even a bug with Craft itself per se, but something I think worth addressing.

The php-intl extension, version 72.1, uses the unicode character \u202f in the IntlDateFormatter::pattern string. This caused us a really weird issue when using the time picker field, since all of those time picker options are formatted based on that string (see CpAsset::633).

For our project, I was taking the value of the timepicker field and passing it into DateTimeHelper::toDateTime(), and it was returning false because date formatters don't know what do do with a string like "2:00\u202fAM". This problem was only happening on our stage and prod servers, and turns out they were both using php-intl:72.1, and not happening on our local and test servers which where running php-intl:71.1 and thus using non-unicode pattern strings like "2:00 AM".

I fixed our side of it by just removing all non-ascii characters in the post body when saving our custom element. However I'm wondering if other people are experiencing this issue as well and not even realizing it.

Not sure where else that IntlDateFormatter is being used in the project, but what do you think about a "fix" to Locale::_getDateTimeFormat by replacing any unicode space character with a normal space?

Again, it's a super weird issue, and because it's a php-extension change I don't even know if it's technically a bug on their end, or if they really meant to use that unicode character instead of a space. I'm posting the problem here because that character is in the jquery timepicker and datepicker options now, and thus the datetime field, and because of that if people are expecting non-unicode strings to work with from those form inputs, they're gonna run into a bad time (like I did lol).

In any case figured ya'll would wanna know about it.

Steps to reproduce

  1. Include the intl php extension, and make sure its version "72.1"
  2. Instantiate a new IntlDateFormatter instance, for example
$dateFormatter = new IntlDateFormatter('en_US', -1, 3);
  1. Echo out the json encoded format string.
echo json_encode($dateFormatter->getPattern());
  1. See that it's h:mm\u202fa.
  2. Instantiate a date time picker field, look at the time options in html, and if you copy one of the option values into a unicode tester online, you'll see it's got that \u202f character in it.

Craft CMS version

4.4.14

PHP version

Stage: 8.1.20, Prod: 8.2.6, Test: 8.1.20, Local: 8.1.7

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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