[f21/master 1/2] Convert strings to unicode in have_word_match (#1146581)
David Shea
dshea at redhat.com
Thu Oct 9 19:44:33 UTC 2014
Sometimes keyboard layout names arrive in anaconda as unicode strings,
and we should handle that.
---
pyanaconda/iutil.py | 6 ++++++
tests/pyanaconda_tests/iutil_test.py | 4 ++++
2 files changed, 10 insertions(+)
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index d78e3c6..3f70860 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -1091,6 +1091,12 @@ def have_word_match(str1, str2):
# non-empty string cannot be found in an empty string
return False
+ # Convert both arguments to unicode if not already
+ if isinstance(str1, str):
+ str1 = str1.decode('utf-8')
+ if isinstance(str2, str):
+ str2 = str2.decode('utf-8')
+
str1 = str1.lower()
str1_words = str1.split()
str2 = str2.lower()
diff --git a/tests/pyanaconda_tests/iutil_test.py b/tests/pyanaconda_tests/iutil_test.py
index 82148d5..1b3e881 100644
--- a/tests/pyanaconda_tests/iutil_test.py
+++ b/tests/pyanaconda_tests/iutil_test.py
@@ -738,3 +738,7 @@ class MiscTests(unittest.TestCase):
self.assertFalse(iutil.have_word_match("", None))
self.assertFalse(iutil.have_word_match(None, ""))
self.assertFalse(iutil.have_word_match(None, None))
+
+ # Compare unicode and str and make sure nothing crashes
+ self.assertTrue(iutil.have_word_match("fête", u"fête champêtre"))
+ self.assertTrue(iutil.have_word_match(u"fête", "fête champêtre"))
--
2.1.0
More information about the anaconda-patches
mailing list