diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index 470a90d5491..d0e6dbe9822 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -1359,8 +1359,15 @@ def size_to_bytes(size): 4096 >>> size_to_bytes('2.2 TB') 2418925581107 + >>> size_to_bytes('.01 TB') + 10995116277 + >>> size_to_bytes('1.b') + 1 + >>> size_to_bytes('1.2E2k') + 122880 """ - size_re = re.compile(r'(?P\d+(\.\d+)?)\s*(?P[eptgmk]?(b|bytes?)?)?$') + # The following number regexp is based on https://stackoverflow.com/questions/385558/extract-float-double-value/385597#385597 + size_re = re.compile(r'(?P(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?)\s*(?P[eptgmk]?(b|bytes?)?)?$') size_match = size_re.match(size.lower()) if size_match is None: raise ValueError("Could not parse string '%s'" % size)