OverZealous / cdnizer

Node module for replacing local links with CDN links, includes fallbacks and customization
MIT License
52 stars 24 forks source link

filenameMin not working, pattern matcher ignores it #2

Closed santthosh closed 10 years ago

santthosh commented 10 years ago

We are trying to replace something like this

<script src="/bower_components/angular/angular.js"></script>

with

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js"></script>

but we keep getting

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.js"></script>

OverZealous commented 10 years ago

Thanks for the bug report.

The issue was simply that it ended up matching too many dots (.). Previously it was matching .min..js. I've got a fix I'm going to push, but you can manually edit your util.js with this, which is the correct fix:

url = url.replace(/(\.min)?(\..+)$/, '.min$2');

This eliminates the extra dot, while still checking for a required leading dot.

It turns out my test case was testing against an existing .min.js, so it the .min was showing up even though the test actually failed. Oops!

I'll push an updated version (along with an updated gulp-cdnizer in a few minutes.

santthosh commented 10 years ago

Fantastic! Thanks, looking forward to the fix

OverZealous commented 10 years ago

Patched version should be available on NPM!

Thanks again for helping to find this, it was rather sneaky!