Problem/Motivation
I believe a regression bug was introduced in the DrupalBootstrapStyles provider class. The conversion of strpos() !== 0 to str_contains() in the parseAssets() method inverted the filtering logic, causing the following behaviour in my case:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/entreprise7pro-bootstrap@3.4.8/dist/css/bootstrap.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@unicorn-fail/drupal-bootstrap-styles@0.0.2/dist/3.1.1/7.x-3.x/drupal-bootstrap.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@unicorn-fail/drupal-bootstrap-styles@0.0.2/dist/3.1.1/8.x-3.x/drupal-bootstrap.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@unicorn-fail/drupal-bootstrap-styles@0.0.2/dist/3.2.0/7.x-3.x/drupal-bootstrap.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@unicorn-fail/drupal-bootstrap-styles@0.0.2/dist/3.2.0/8.x-3.x/drupal-bootstrap.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@unicorn-fail/drupal-bootstrap-styles@0.0.2/dist/3.3.1/7.x-3.x/drupal-bootstrap.css" />
I believe the logic is inverted: strpos() !== 0 checks if the string starts at position 0, while str_contains() checks if the string contains the pattern anywhere. The correct PHP 8+ conversion should use str_starts_with().
On top of that, there is no drupal-bootstrap.css loaded for newer Bootstrap versions (3.4.2-3.4.8) so if I understand correctly, we need to map these versions to the latest available version (3.4.1)
Steps to reproduce
- Install version 8.x-3.38 of this theme
- Configure jsDelivr as CDN
- Configure version 3.4.8
- View the HTML source of any page
- Observe multiple duplicate
drupal-bootstrap.cssfiles being loaded from different versions and branches
Proposed resolution
- Fix the inverted logic: change
str_contains()to!str_starts_with() - Add
mapVersion()method to map Bootstrap 3.4.2-3.4.8 to available version 3.4.1 (following the pattern inBootstrap::glyphicons())
Remaining tasks
- Review and test patch
- Commit fix
User interface changes
None.
API changes
None. Restores original intended behavior.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | drupal-bootstrap-styles-3558024-3.patch | 1.61 KB | jvandooren |
Issue fork bootstrap-3558024
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jvandooren commentedHere is already a patch to fix this. Will also try to provide the changes in an issue fork.
Comment #3
jvandooren commentedCoding standards fix
Comment #4
tobiasbI do not see 3.4.1 in https://www.npmjs.com/package/@unicorn-fail/drupal-bootstrap-styles/v/0...., did you mean 3.4.0?
Comment #5
jvandooren commentedHi,
It has been a while, but I'm pretty sure I meant 3.4.1. This is also backed by the fact that the mapping to 3.4.1 is also done in https://git.drupalcode.org/project/bootstrap/-/blob/8.x-3.38/src/Bootstrap.php?ref_type=tags#L1213 for example.
So I suppose it must have existed at some point? Not sure what happened here.
Comment #7
joseph.olstadLooks good, thanks for reporting and fixing!
Comment #9
joseph.olstadSee the release notes and please report related issues (if any noticed).
https://www.drupal.org/project/bootstrap/releases/8.x-3.40