-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1558 from heartsucker/flash-fixes
Flash message fixes
- Loading branch information
Showing
14 changed files
with
142 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
import source | ||
import unittest | ||
import util | ||
from util import PathException | ||
|
||
|
||
class TestUtil(unittest.TestCase): | ||
|
||
def test_svg_valid(self): | ||
with source.app.app_context(): | ||
res = util.svg('success_checkmark.svg') | ||
self.assertIn('<svg', res) | ||
|
||
def test_svg_bad_extension(self): | ||
with source.app.app_context(): | ||
with self.assertRaises(PathException): | ||
util.svg('config.py') | ||
|
||
def test_svg_bad_path(self): | ||
with source.app.app_context(): | ||
with self.assertRaises(PathException): | ||
util.svg('../../../../etc/hosts') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from os import path | ||
|
||
from flask import current_app | ||
|
||
|
||
class PathException(Exception): | ||
|
||
"""An exception raised by `util.verify` when it encounters a bad path. A path | ||
can be bad when it is not absolute or not normalized. | ||
""" | ||
pass | ||
|
||
|
||
def svg(filename): | ||
"""Safely takes a filename and returns the contents of the file in the | ||
static directory as a string. | ||
""" | ||
|
||
if not filename.endswith('.svg'): | ||
raise PathException('File must have .svg extension, but got {}' | ||
.format(filename)) | ||
|
||
target_path = path.join(path.abspath(current_app.static_folder), 'i', 'svg', | ||
filename) | ||
if not path.isabs(target_path): | ||
raise PathException('Expected path to SVG to the absolute and ' | ||
'normalized, but found {}'.format(target_path)) | ||
|
||
with open(target_path) as f: | ||
return f.read() |