Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeDecodeError if render_favicon is used #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bowerstatic/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ def renderer(self, resource):
def make_renderer(renderer):
if isinstance(renderer, string_types):
def string_renderer(resource):
return renderer.format(url=resource.url(),
content=resource.content())
if '{content}' in renderer:
return renderer.format(content=resource.content())
else:
return renderer.format(url=resource.url())
return string_renderer

if callable(renderer):
Expand Down
7 changes: 7 additions & 0 deletions bowerstatic/tests/bower_components/favicon_main/.bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "favicon_main",
"version": "1.0.0",
"main": [
"dist/favicon.ico"
]
}
7 changes: 7 additions & 0 deletions bowerstatic/tests/bower_components/favicon_main/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "favicon_main",
"version": "1.0.0",
"main": [
"dist/favicon.ico"
]
}
Binary file not shown.
24 changes: 24 additions & 0 deletions bowerstatic/tests/test_injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,3 +744,27 @@ def wsgi(environ, start_response):
assert response.body == (
b'<html><head><script type="text/javascript">/* jquery.js 2.1.1 */\n'
b'</script></head><body>Hello!</body></html>')


def test_injector_favicon_renderer():
bower = bowerstatic.Bower()

components = bower.components('components', os.path.join(
os.path.dirname(__file__), 'bower_components'))

def wsgi(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')])
include = components.includer(environ)
include('favicon_main')
return [b'<html><head></head><body>Hello!</body></html>']

injector = bower.injector(wsgi)

c = Client(injector)

response = c.get('/')
assert response.body == (
b'<html><head>'
b'<link rel="shortcut icon" '
b'href="/bowerstatic/components/favicon_main/1.0.0/dist/favicon.ico">'
b'</head><body>Hello!</body></html>')