Skip to content

Commit

Permalink
Merge pull request #3407 from /issues/3401/2
Browse files Browse the repository at this point in the history
Fixes #3401 - Don't modify the file_path inside bust_cache
  • Loading branch information
Mike Taylor authored Jul 21, 2020
2 parents 647f923 + 309b5ac commit f51692e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion tests/unit/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ def test_bust_cache_localhost():

def test_bust_cache_production_missing_file():
"""Test for cache_bust the path is missing."""
expected = 'punkcat/nowhere?missing_file'
expected = '/punkcat/nowhere?missing_file'
expected2 = 'punkcat/nowhere?missing_file'
webcompat.app.config['LOCALHOST'] = None
assert bust_cache('/punkcat/nowhere') == expected
assert bust_cache('punkcat/nowhere') == expected2


def test_bust_cache_production_file_exists(tmpdir):
Expand All @@ -151,4 +153,6 @@ def test_bust_cache_production_file_exists(tmpdir):
file_path = tmpdir.join('space.js')
file_path.write_text('punkcat', encoding='utf-8')
expected = 'space.js' + '?501753e94c8bfbbbd53c792c9688c8b5'
expected2 = '/space.js' + '?501753e94c8bfbbbd53c792c9688c8b5'
assert bust_cache('space.js') == expected
assert bust_cache('/space.js') == expected2
5 changes: 3 additions & 2 deletions webcompat/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def bust_cache(file_path):
"""
if app.config['LOCALHOST']:
return file_path
trimmed_file_path = file_path
if file_path.startswith('/'):
file_path = file_path[1:]
absolute_path = os.path.join(STATIC_PATH, file_path)
trimmed_file_path = file_path[1:]
absolute_path = os.path.join(STATIC_PATH, trimmed_file_path)
return file_path + '?' + get_checksum(absolute_path)


Expand Down

0 comments on commit f51692e

Please sign in to comment.