Skip to content

Commit 4eb8e9a

Browse files
author
Nick Joyce
committed
Ensure the correct url generation with leading/trailing slashes in config.
Fixes: #1
1 parent 3c99899 commit 4eb8e9a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

flask_assetrev/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ def get_asset_url(self, asset):
144144
asset_file = os.path.join(self.base_path, asset_file)
145145

146146
if self.base_url:
147-
return self.base_url + asset_file
147+
return '/'.join([
148+
self.base_url.rstrip('/'),
149+
asset_file.lstrip('/'),
150+
])
148151

149152
return url_for(
150153
'static',

test/test_assetrev.py

+18
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,21 @@ def test_missing_asset(self):
112112
asset_url('missing.js')
113113

114114
self.assertEqual(ctx.exception.asset_file, 'missing.js')
115+
116+
# https://github.com/njoyce/flask-assetrev/issues/1
117+
def test_trailing_slash(self):
118+
"""
119+
Handle trailing slashes in config
120+
"""
121+
app = make_app(config={
122+
'ASSETREV_BASE_URL': '//cdn.myapp.com/',
123+
'ASSETREV_BASE_PATH': '/foobar',
124+
})
125+
126+
with app.test_request_context():
127+
import flask_assetrev as assetrev
128+
129+
self.assertEqual(
130+
assetrev.asset_url('app.js'),
131+
'//cdn.myapp.com/foobar/app.deadb33f.js'
132+
)

0 commit comments

Comments
 (0)