Not load external CSS with the characters =,+| in the URL

Created on 26 February 2023, over 1 year ago
Updated 11 March 2023, over 1 year ago

Problem/Motivation

Add a Google Fonts in my theme using the library.

mytheme.libraries.yml

base:
  version: VERSION
  css:
    theme:
      //fonts.googleapis.com/css?family=Montserrat:400,500,600,700|Work+Sans:400,500,600,700: { type: external }

and when activating the option "Deferred CSS Execution: Use JS to load CSS" in module advagg_mod,
All CSS are loaded asynchronous except that of the Google Fonts.

Steps to reproduce

1. Add any CSS file containing characters such as =,+|.
2. Go page /admin/config/development/performance/advagg/mod
3. Active "Deferred CSS Execution: Use JS to load CSS" and "Use JS to load external CSS"
4. Clear cache
5. Check the HTML of the page, which must generate the following code:

<link rel="stylesheet" media="all" href="//fonts.googleapis.com/css?family=Montserrat:400,500,600,700|Work+Sans:400,500,600,700" as="style" onload="this.rel='stylesheet'">
<noscript><link rel="stylesheet" media="all" href="//fonts.googleapis.com/css?family=Montserrat:400,500,600,700|Work+Sans:400,500,600,700" /></noscript>

Proposed resolution

Change regular expression and add these characters,
in file advagg_mod/src/Asset/DeferCss.php line 53

$pattern = '/<link rel=["\']stylesheet["\'](.*)(href="[a-zA-Z0-9\/_\.\-\?\:\=\|\,\+]*")(.*)\/\>/';
πŸ› Bug report
Status

Active

Version

5.0

Component

Modifier

Created by

πŸ‡ΊπŸ‡ΎUruguay ruby232 Montevideo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024