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

  1. Install version 8.x-3.38 of this theme
  2. Configure jsDelivr as CDN
  3. Configure version 3.4.8
  4. View the HTML source of any page
  5. Observe multiple duplicate drupal-bootstrap.css files being loaded from different versions and branches

Proposed resolution

  1. Fix the inverted logic: change str_contains() to !str_starts_with()
  2. Add mapVersion() method to map Bootstrap 3.4.2-3.4.8 to available version 3.4.1 (following the pattern in Bootstrap::glyphicons())

Remaining tasks

  • Review and test patch
  • Commit fix

User interface changes

None.

API changes

None. Restores original intended behavior.

Data model changes

None.

Issue fork bootstrap-3558024

Command icon 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

jvandooren created an issue. See original summary.

jvandooren’s picture

StatusFileSize
new1.61 KB

Here is already a patch to fix this. Will also try to provide the changes in an issue fork.

jvandooren’s picture

StatusFileSize
new1.61 KB

Coding standards fix

tobiasb’s picture

jvandooren’s picture

Hi,

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.

  • joseph.olstad committed b9afa1d0 on 8.x-3.x
    fix: #3558024 DrupalBootstrapStyles: Inverted filter logic causes...
joseph.olstad’s picture

Status: Active » Fixed

Looks good, thanks for reporting and fixing!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

joseph.olstad’s picture

See the release notes and please report related issues (if any noticed).
https://www.drupal.org/project/bootstrap/releases/8.x-3.40