No Code Attached Yet bug
avatar joomdonation
joomdonation
20 Jan 2025

Steps to reproduce the issue

Use the code below to load Stripe JS:

$wa = Factory::getDocument()->getWebAssetManager();
$wa->registerAndUseScript('sesame.stripepay', 'https://js.stripe.com/v3/');

Expected result

Stripe JS loaded properly

Actual result

Stripe JS is not loaded. The script element has wrong src like below

<script src="/joomla/root/path/https://js.stripe.com/v3/?12f2b9" data-asset-name="sesame.stripepay"></script>

System information (as much as possible)

Additional comments

  • Remove / at the end of the URL solves the issue. The code $wa->registerAndUseScript('sesame.stripepay', 'https://js.stripe.com/v3'); works properly
  • The line of code causes bug
    // Asset for the ES modules may give us a folder for ESM import map
    if (str_ends_with($path, '/') && !str_starts_with($path, '.')) {
    $path = Uri::root(true) . '/' . $path;
    }

Ping @Fedik

avatar joomdonation joomdonation - open - 20 Jan 2025
avatar joomla-cms-bot joomla-cms-bot - change - 20 Jan 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 20 Jan 2025
avatar Fedik Fedik - change - 20 Jan 2025
Labels Added: bug
avatar Fedik Fedik - labeled - 20 Jan 2025
avatar Elfangor93
Elfangor93 - comment - 20 Jan 2025

Maybe we should check for the appearance of 'http' or 'https' in $path before changing it?

avatar C-Lodder
C-Lodder - comment - 21 Jan 2025

Could check if the $path is NOT a URL:

if (str_ends_with($path, '/') && !str_starts_with($path, '.') && !filter_var($path, FILTER_VALIDATE_URL)) { 
   $path = Uri::root(true) . '/' . $path; 
}
avatar Fedik
Fedik - comment - 21 Jan 2025

You both very close to solution, but there actualy 3-rd way :)
I will do PR later.

avatar Fedik Fedik - change - 24 Jan 2025
Status New Closed
Closed_Date 0000-00-00 00:00:00 2025-01-24 10:38:22
Closed_By Fedik
avatar Fedik Fedik - close - 24 Jan 2025
avatar Fedik
Fedik - comment - 24 Jan 2025

Please test #44774

Add a Comment

Login with GitHub to post a comment