Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#54922 closed defect (bug) (fixed)

Normalizing CSS also catches CSS IDs instead of only URLs

Reported by: mahype's profile mahype Owned by: audrasjb's profile audrasjb
Milestone: 5.9.1 Priority: normal
Severity: normal Version: 5.9
Component: Script Loader Keywords: has-patch has-unit-tests has-testing-info commit fixed-major
Focuses: Cc:

Description

The function _wp_normalize_relative_css_links which was introduced in WordPress 5.9.0 does not only preg matching urls, it also matches HTML ids.

The CSS property

clip-path: url(#image1);

will be replaced by

clip-path: url(/relative_url/#image1);

The clip path wont work anymore after this replacement.

Change History (12)

#1 @SergeyBiryukov
3 years ago

  • Milestone changed from Awaiting Review to 5.9.1

#2 @costdev
3 years ago

Test Report

Env

  • Web Server: Apache
  • WordPress: 6.0-alpha-52448-src
  • Browser: Chrome
  • OS: Linux
  • Theme: Twenty Twenty-Two
  • Plugins: None activated

Steps to test

  1. Make the following call:
    echo _wp_normalize_relative_css_links( 'clip-path: url(#image1);', get_stylesheet_uri() );
    

Results

  • Expected: clip-path: url(#image1);
  • Actual: clip-path: url(/wordpress-develop/src/wp-content/themes/twentytwentytwo/#image1);
  • Reproduced ✅ Expected and actual do not match.

This ticket was mentioned in PR #2260 on WordPress/wordpress-develop by costdev.


3 years ago
#3

  • Keywords has-patch has-unit-tests added

#4 @audrasjb
3 years ago

Thanks @mahype for reporting this.
The above PR looks good to me.

We should also implement str_starts_with on other places for better consistency in a follow-up 6.0 ticket.

#5 @Boniu91
3 years ago

  • Keywords needs-testing has-testing-info added

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


3 years ago

#7 @audrasjb
3 years ago

  • Keywords commit added; needs-testing removed
  • Owner set to audrasjb
  • Status changed from new to assigned

I tested the proposed PR and it fixes the issue.

Using:

echo _wp_normalize_relative_css_links( 'clip-path: url(#image1);', get_stylesheet_uri() );

Result before patch:
clip-path: url(/552/wordpress-13/wp-content/themes/twentytwenty/#image1);

Result after patch:
clip-path: url(#image1);

The patch was reviewed by @SergeyBiryukov. It passes the unit tests.
Self assigning for commit.

#8 @audrasjb
3 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 52695:

Script Loader: Prevent normalizing HTML IDs in _wp_normalize_relative_css_links().

This change fixes an issue where _wp_normalize_relative_css_links() was not only matching urls, but also HTML IDs.

Follow-up to [52036].

Props mahype, costdev, audrasjb, SergeyBiryukov.
Fixes #54922.

#9 @audrasjb
3 years ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for backport consideration.

#11 @audrasjb
3 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 52714:

Script Loader: Prevent normalizing HTML IDs in _wp_normalize_relative_css_links().

This change fixes an issue where _wp_normalize_relative_css_links() was not only matching urls, but also HTML IDs.

Follow-up to [52036].

Props mahype, costdev, audrasjb, SergeyBiryukov.
Merges [52695] to the 5.9 branch.
Fixes #54922.

#12 @audrasjb
3 years ago

In 52715:

Script Loader: Prevent normalizing HTML IDs in _wp_normalize_relative_css_links().

This change fixes an issue where _wp_normalize_relative_css_links() was not only matching urls, but also HTML IDs.

Follow-up to [52036].

Props mahype, costdev, audrasjb, SergeyBiryukov.
Merges [52695] to the 5.9 branch.
Fixes #54922.

Note: See TracTickets for help on using tickets.