Permalink
Browse files

Merge pull request #476 from mmccurdy/master

Small tweaks to fix certain broken Layer image URLs
  • Loading branch information...
nvh committed Mar 10, 2017
2 parents fc55495 + 5cc8e5b commit 475253af8fe3055f906b3497eee67c933615d5e6
Showing with 21 additions and 2 deletions.
  1. +2 −1 framer/Layer.coffee
  2. +1 −1 framer/Utils.coffee
  3. +17 −0 test/tests/LayerTest.coffee
  4. +1 −0 test/tests/UtilsTest.coffee
View
@@ -719,7 +719,8 @@ class exports.Layer extends BaseClass
# imageUrl = Config.baseUrl + imageUrl
if @_alwaysUseImageCache is false and Utils.isLocalAssetUrl(imageUrl)
imageUrl += "?nocache=#{NoCacheDateKey}"
imageUrl += if /\?/.test(imageUrl) then '&' else '?'
imageUrl += "nocache=#{NoCacheDateKey}"
# As an optimization, we will only use a loader
# if something is explicitly listening to the load event
View
@@ -369,7 +369,7 @@ Utils.isRelativeUrl = (url) ->
not /^([a-zA-Z]{1,8}:\/\/).*$/.test(url)
Utils.isLocalServerUrl = (url) ->
return url.indexOf("127.0.0.1") isnt -1 or url.indexOf("localhost") isnt -1
return /[a-zA-Z]{1,8}:\/\/127\.0\.0\.1/.test(url) or /[a-zA-Z]{1,8}:\/\/localhost/.test(url)
Utils.isLocalUrl = (url) ->
return true if Utils.isFileUrl(url)
@@ -276,6 +276,23 @@ describe "Layer", ->
layer.style["background-image"].indexOf("data:").should.not.equal(-1)
layer.style["background-image"].indexOf("?nocache=").should.equal(-1)
it "should append nocache with an ampersand if url params already exist", (done) ->
prefix = "../"
imagePath = "static/test.png?param=foo"
fullPath = prefix + imagePath
layer = new Layer
layer.on Events.ImageLoaded, ->
layer.style["background-image"].indexOf(imagePath).should.not.equal(-1)
layer.style["background-image"].indexOf("file://").should.not.equal(-1)
layer.style["background-image"].indexOf("&nocache=").should.not.equal(-1)
done()
layer.image = fullPath
layer.image.should.equal fullPath
it "should cancel loading when setting image to null", (done) ->
prefix = "../"
@@ -430,6 +430,7 @@ describe "Utils", ->
Utils.isLocalServerUrl("https://127.0.0.1/index.html").should.equal(true)
Utils.isLocalServerUrl(".././Desktop/index.html").should.equal(false)
Utils.isLocalServerUrl("https://apple.com/index.html").should.equal(false)
Utils.isLocalServerUrl("https://apple.com/?url=http%3A%2F%2F127.0.0.1").should.equal(false)
describe "isLocalAssetUrl", ->
it "should work", ->

0 comments on commit 475253a

Please sign in to comment.