[blivet f20/master 2/5] Allow non-ASCII characters in the size spec

David Shea dshea at redhat.com
Thu Nov 21 20:32:59 UTC 2013


---
 blivet/size.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/blivet/size.py b/blivet/size.py
index d9af722..7c03c2e 100644
--- a/blivet/size.py
+++ b/blivet/size.py
@@ -75,7 +75,11 @@ def _parseSpec(spec):
     if not spec:
         raise ValueError("invalid size specification", spec)
 
-    m = re.match(r'(-?\s*[0-9.]+)\s*([A-Za-z]*)$', spec.strip())
+    # This regex isn't ideal, since \w matches both letters and digits,
+    # but python doesn't provide a means to match only Unicode letters.
+    # Probably the worst that will come of it is that bad specs will fail
+    # more confusingly.
+    m = re.match(r'(-?\s*[0-9.]+)\s*(\w*)$', spec.decode("utf-8").strip(), flags=re.UNICODE)
     if not m:
         raise ValueError("invalid size specification", spec)
 
@@ -102,6 +106,8 @@ def _parseSpec(spec):
 def xlate_size(spec):
     """Translate English size specifiers into the current locale."""
 
+    # Keep the non-unicode A-Za-z here since the input is English and
+    # this lets us be lazier about matching the non-specifier part
     m = re.match(r'(.*?)([A-Za-z]*)$', spec.strip())
     if not m:
         raise ValueError("invalid size specification", spec)
-- 
1.8.4.2



More information about the anaconda-patches mailing list