Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include mbstring polyfill #5511

Open
swissspidy opened this issue Oct 16, 2020 · 6 comments
Open

Include mbstring polyfill #5511

swissspidy opened this issue Oct 16, 2020 · 6 comments
Labels
Enhancement New feature or improvement of an existing one P2 Low priority WS:Core Work stream for Plugin core

Comments

@swissspidy
Copy link
Collaborator

Feature description

I originally opened this at GoogleForCreators/web-stories-wp#4898 but this might be useful as part of the AMP plugin itself.

if (self::AMP_ENCODING !== strtolower($this->originalEncoding)) {
$target = function_exists('mb_convert_encoding')
? mb_convert_encoding($source, self::AMP_ENCODING, $this->originalEncoding)
: false;
}

The Document class uses mb_convert_encoding to fix the encoding if needed. That function is part of the mbstring extension which can be missing or outdated on certain servers.

For those cases, https://github.com/symfony/polyfill-mbstring/ might be useful.

Caveats:

  1. Might need to use PHP-Scoper to prefix the classes and prevent conflicts with other plugins using this polyfill
  2. Might need to use mcaskill/composer-exclude-files to prevent files from being loaded automatically and steer that ourselves.

Curious to hear thoughts on this.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

@swissspidy swissspidy added the Enhancement New feature or improvement of an existing one label Oct 16, 2020
@westonruter
Copy link
Member

This is only necessary if a site is not using UTF-8 already, correct?

It looks like 95% of sites use UTF-8 already.

So probably very few sites would ever encounter an issue here?

@westonruter westonruter added the P2 Low priority label Oct 16, 2020
@swissspidy
Copy link
Collaborator Author

Uhm, probably? Not sure how many sites have odd blog_charset configurations.

@westonruter
Copy link
Member

Did it come up as an actual problem for Web Stories?

@swissspidy
Copy link
Collaborator Author

We had a couple of reports about mangled special chars in the past, where the encoding was off. But we'd also use mb_convert_encoding for other cases, such as GoogleForCreators/web-stories-wp#4859

@westonruter westonruter added the WS:Core Work stream for Plugin core label Oct 22, 2020
@westonruter
Copy link
Member

A question was raised in php-css-parser about whether mbstring should be made a hard-requirement: MyIntervals/PHP-CSS-Parser#254. Nevertheless, polyfill-mbstring requires PHP 7.1+ so we can't use it anyway.

@swissspidy
Copy link
Collaborator Author

We use an older version (1.18) which still supports PHP 5.6+. So does 1.19 I think (at least from what I can tell after looking at symfony/polyfill-mbstring@39d483b)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or improvement of an existing one P2 Low priority WS:Core Work stream for Plugin core
Projects
None yet
Development

No branches or pull requests

2 participants