Make WordPress Core

Opened 3 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#61909 closed defect (bug) (fixed)

Script Loader: Do not normalize absolute-paths in `_wp_normalize_relative_css_links()`.

Reported by: scholdstrom's profile scholdstrom Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.7 Priority: normal
Severity: normal Version: trunk
Component: Script Loader Keywords: has-patch has-unit-tests
Focuses: css Cc:

Description

Currently _wp_normalize_relative_css_links() normalizes all non-absolute URLs regardless if it's a relative-path or an absolute-path. The normalization should only happen for relative-paths (paths without a leading /) and not for absolute paths.

See RFC1808, Section 4, Step 4 and since it's against this RFC I'll classify this as a bug but it could just as likely be classified as a feature.

Currently using an absolute path would normalize the URL like this

-'p {background:url( "/image0.svg" );}'
+'p {background:url( "/wp-content/themes/test//image0.svg" );}'

Theme developers referencing urls in CSS would always use relative links so that hostname isn't fixed at build time. At the moment theme developers wanting to support wp_maybe_inline_styles() have to use relative paths and would not be able to set a base path for assets with Webpack publicPah option. I believe this is required for using webpack lazy loaded chunks.

I do believe this is more commonly used by agencies building websites.

Attachments (1)

61909.diff (1.4 KB) - added by scholdstrom 3 weeks ago.

Download all attachments as: .zip

Change History (5)

@scholdstrom
3 weeks ago

This ticket was mentioned in PR #7228 on WordPress/wordpress-develop by oxyc.


3 weeks ago
#1

  • Keywords has-patch has-unit-tests added

Currently _wp_normalize_relative_css_links() normalizes all non-absolute URLs regardless if it's a relative-path or an absolute-path. The normalization should only happen for relative-paths (paths without a leading /) and not for absolute paths.

Trac ticket: https://core.trac.wordpress.org/ticket/61909

#2 @SergeyBiryukov
3 weeks ago

  • Milestone changed from Awaiting Review to 6.7

#3 @SergeyBiryukov
3 weeks ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 58932:

Script Loader: Do not normalize absolute paths in inline block styles CSS.

_wp_normalize_relative_css_links() used to normalize all non-absolute URLs regardless of whether it's a relative path or an absolute path. The normalization should only happen for relative paths (paths without a leading /) and not for absolute paths.

Reference: RFC 1808, Section 4, Step 4.

Follow-up to [52036], [52695], [52754], [55658], [55669].

Props scholdstrom.
Fixes #61909.

@SergeyBiryukov commented on PR #7228:


3 weeks ago
#4

Thanks for the PR! Merged in r58932.

Note: See TracTickets for help on using tickets.