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

Google Fonts: formating the fontFamily block attribute fails if it's not a string #38311

Closed
jhnstn opened this issue Jul 11, 2024 · 5 comments · Fixed by #38321
Closed

Google Fonts: formating the fontFamily block attribute fails if it's not a string #38311

jhnstn opened this issue Jul 11, 2024 · 5 comments · Fixed by #38321
Assignees
Labels
Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". [Feature] Google Fonts [Platform] Atomic [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] High [Status] Priority Review Triggered The guild in charge of triage has been notified of this issue in Slack Triaged [Type] Bug When a feature is broken and / or not performing as intended

Comments

@jhnstn
Copy link
Member

jhnstn commented Jul 11, 2024

Impacted plugin

Jetpack

Quick summary

Any block can add the attribute fontFamily as something other than a string.
However, format_font() method assumes the attribute is a string https://github.com/Automattic/jetpack/blame/trunk/projects/plugins/jetpack/modules/google-fonts/current/class-jetpack-google-font-face.php#L149

This can cause issues when trying to render a block which can in turn prevent updating a post.

This was found while trying to solve an issue where a widget contained a block that used fontFamily object attribute.
The specific block attribute can be seen here https://plugins.trac.wordpress.org/browser/easy-quotes/trunk/build/block.json#L93

Trying to remove that block from a widget results in the error
PHP Fatal error: Uncaught TypeError: strtolower(): Argument #1 ($string) must be of type string, array given in /wordpress/plugins/jetpack/13.7-a.1/modules/google-fonts/current/class-jetpack-google-font-face.php:149

Steps to reproduce

Steps

  1. Install a plugin that has adds a block which defines a fontFamily that is not a string ( https://wordpress.org/plugins/easy-quotes/ for example )
  2. Add the block to a page of a WordPress.com site
  3. Try saving the page

A clear and concise description of what you expected to happen.

The page should be saved

What actually happened

The API returns an error and the post is not saved.

Impact

One

Available workarounds?

No but the platform is still usable

Platform (Simple and/or Atomic)

Atomic

Logs or notes

Probably just need to do a string check here https://github.com/Automattic/jetpack/blame/trunk/projects/plugins/jetpack/modules/google-fonts/current/class-jetpack-google-font-face.php#L124

@jhnstn jhnstn added [Type] Bug When a feature is broken and / or not performing as intended Needs triage Ticket needs to be triaged labels Jul 11, 2024
@github-actions github-actions bot added [Status] Priority Review Triggered The guild in charge of triage has been notified of this issue in Slack [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Platform] Atomic [Pri] High labels Jul 11, 2024
@jhnstn
Copy link
Member Author

jhnstn commented Jul 11, 2024

Originally reported here: 8470578-zd-a8c

Copy link
Contributor

Support References

This comment is automatically generated. Please do not edit it.

  • 8470578-zen
@github-actions github-actions bot added the Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". label Jul 11, 2024
@jeherve
Copy link
Member

jeherve commented Jul 12, 2024

@Automattic/lego Is that something you could look at?

Thank you!

@jeherve jeherve added Triaged and removed Needs triage Ticket needs to be triaged labels Jul 12, 2024
@fushar
Copy link
Contributor

fushar commented Jul 12, 2024

Thanks @jeherve.

@arthur791004 -- since it looks like an easy fix, and you're the one most familiar with this area, would mind looking at it sometime next week? Let's still prioritize the ETK migration, though. cc: @taipeicoder

@jhnstn
Copy link
Member Author

jhnstn commented Jul 12, 2024

I opened a PR with the fix. I added tests but was having a hard time running them locally. I'll be AFK next week so you can take over that PR.

Edit: Tests are passing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". [Feature] Google Fonts [Platform] Atomic [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] High [Status] Priority Review Triggered The guild in charge of triage has been notified of this issue in Slack Triaged [Type] Bug When a feature is broken and / or not performing as intended
3 participants