ember-cli / broccoli-asset-rev

Broccoli plugin to add fingerprint checksums and CDN URLs to your assets
MIT License
87 stars 84 forks source link

Fingerprint prepend mysteriously added in wrong place in ONE file only #116

Closed abirtley closed 6 years ago

abirtley commented 7 years ago

Using Ember 2.8 and broccoli-asset-rev 2.5.0. I have added a prepend when in production to point to my AWS Cloudfront distribution. Everything works fine - except that one image (and no others) gets its fingerprinted URL generated incorrectly.

Here is the html code for that image: <img src="/assets/images/agreeing.png">

And here is what was generated: <img src="/https://testlawfirm.settify.com.au/assets/images/agreeing-b43abdb947643080f692a1dfdebc4394.png">

(Notice the unwanted "/" at the start of the URL)

Every other image works just fine, eg: <img src="/assets/images/telephone.png"> becomes <img src="https://testlawfirm.settify.com.au/assets/images/telephone-affbcf79f7bf3f4765496d2fcd4ae084.png">

the assetMap.json file gave me no clues: "assets/images/agreeing.png": "assets/images/agreeing-b43abdb947643080f692a1dfdebc4394.png", "assets/images/telephone.png": "assets/images/telephone-affbcf79f7bf3f4765496d2fcd4ae084.png",

My workaround was to remove the initial / from the one offending img's src, like so: <img src="assets/images/agreeing.png">

But I doubt this is expected behaviour, especially as every other image in my app has a src beginning with /assets/images/

For what it's worth, ember-cli-build.js contains (relevantly) the following parameters: params.fingerprint = { enabled: true, prepend: cdnURL + "/", generateAssetMap: true } cdnURL in this case was https://testlawfirm.settify.com.au

Unfortunately, I have no suggestions as to how this can be reproduced, since this only happens on one image and I can't see a reason why.

abirtley commented 6 years ago

I've figured it out - you need to be consistent in your filenames throughout the project. If in one place you write assets/images/agreeing.png but in another you write /assets/images/agreeing.png, then your second string is going to get rewritten using the rewrite value of the first string (since the first string is a subset of the second string). This leads to the incorrect slash at the start of the second rewritten URL.

I've added a suggestion in the broccoli-asset-rewrite project, and am closing this issue here.