tattersoftware / codeigniter4-assets

Asset handling for CodeIgniter 4
MIT License
50 stars 12 forks source link

Issue: Outputted URIs contain \ backslash on Windows #48

Closed craigrodway closed 2 years ago

craigrodway commented 2 years ago

Hi!

Given the code:

<?= \Tatter\Assets\Asset::createFromPath('main.css') ?>
<?= \Tatter\Assets\Asset::createFromPath('main.js') ?>

It now produces:

<link href="http://example.com/assets\main.css?v=1644518679" rel="stylesheet" type="text/css" />
<script src="http://example.com/assets\main.js?v=1644518679" type="text/javascript"></script>

While it does seem to work, and browsers are very forgiving, it's not correct.

I think the issue is here: https://github.com/tattersoftware/codeigniter4-assets/blob/develop/src/Asset.php#L57

self::$config->uri       = rtrim(self::$config->uri, '/\\') . DIRECTORY_SEPARATOR;

This line should probably revert back to a simple '/' value instead of DIRECTORY_SEPARATOR.

MGatner commented 2 years ago

You are very right. I had some issues on Windows and did a pretty global application of DIRECTORY_SEPARATOR, must have accidentally scooped this one up! Care to send a PR?

craigrodway commented 2 years ago

No worries, all done! :)

MGatner commented 2 years ago

Thanks for that! Quick and clean fix. I'm traveling but will release this bugfix when I'm home.