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

Output: optimize fix_malformed_script_link_tags() regex #12159

Merged
merged 2 commits into from
Aug 24, 2022

Conversation

swissspidy
Copy link
Collaborator

Context

See #12158.

This error with a blank screen can happen when the preg_replace_callback() call in HTML::fix_malformed_script_link_tags() errored and thus an empty content was returned.

In my testing this all happened because

  1. The existing regex was very inefficient and had catastrophic backtracking
  2. We simply overrode $content even if there was an error

Summary

This PR optimizes the preg_replace_callback usage in fix_malformed_script_link_tags() in two ways:

  1. Use optimized regex that is simpler to read (using a back reference) and has better performance
  2. Return original $content if there was an error with the regex replacement

Relevant Technical Choices

Removed some dead code

To-do

N/A

User-facing changes

N/A

Testing Instructions

  • This is a non-user-facing change and requires no QA

This PR can be tested by following these steps:

Reviews

Does this PR have a security-related impact?

No

Does this PR change what data or activity we track or use?

No

Does this PR have a legal-related impact?

No

Checklist

  • This PR addresses an existing issue and I have linked this PR to it in ZenHub
  • I have tested this code to the best of my abilities
  • I have verified accessibility to the best of my abilities (docs)
  • I have verified i18n and l10n (translation, right-to-left layout) to the best of my abilities
  • This code is covered by automated tests (unit, integration, and/or e2e) to verify it works as intended (docs)
  • I have added documentation where necessary
  • I have added a matching Type: XYZ label to the PR

Fixes #12158

@swissspidy swissspidy added Type: Bug Something isn't working PHP Pull requests that update PHP code Group: WordPress Changes related to WordPress or Gutenberg integration AMP Output Issues related to AMP output and validation Pod: WP labels Aug 23, 2022
@googleforcreators-bot
Copy link
Collaborator

Plugin builds for 839bc90 are ready 🛎️!

@swissspidy swissspidy merged commit 63c6b83 into main Aug 24, 2022
@swissspidy swissspidy deleted the fix/12158-html-output branch August 24, 2022 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AMP Output Issues related to AMP output and validation Group: WordPress Changes related to WordPress or Gutenberg integration PHP Pull requests that update PHP code Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Output: empty body when fix_malformed_script_link_tags() regex fails
3 participants