Skip to content

Commit

Permalink
Fix binary file check
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Aug 2, 2018
1 parent deba605 commit 6b86ed5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/util/__init__.py
Expand Up @@ -65,7 +65,7 @@
gzip_magic = b'\x1f\x8b'
bz2_magic = b'BZh'
DEFAULT_ENCODING = os.environ.get('GALAXY_DEFAULT_ENCODING', 'utf-8')
NULL_CHAR = '\000'
NULL_CHAR = b'\000'
BINARY_CHARS = [NULL_CHAR]
FILENAME_VALID_CHARS = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

Expand Down
7 changes: 4 additions & 3 deletions lib/galaxy/util/checkers.py
Expand Up @@ -4,7 +4,7 @@
import tarfile
import zipfile

from six import StringIO
from six import BytesIO
from six.moves import filter

from galaxy import util
Expand Down Expand Up @@ -39,6 +39,7 @@ def check_html(file_path, chunk=None):
# TODO: Potentially reading huge lines into string here, this should be
# reworked.
for line in temp:
line = util.unicodify(line)
lineno += 1
matches = regexp1.search(line) or regexp2.search(line) or regexp3.search(line) or regexp4.search(line) or regexp5.search(line)
if matches:
Expand All @@ -55,9 +56,9 @@ def check_html(file_path, chunk=None):
def check_binary(name, file_path=True):
# Handles files if file_path is True or text if file_path is False
if file_path:
temp = open(name, "U")
temp = open(name, "rb")
else:
temp = StringIO(name)
temp = BytesIO(name)
try:
return util.is_binary(temp.read(1024))
finally:
Expand Down

0 comments on commit 6b86ed5

Please sign in to comment.