Support Unicode characters in configuration values
authorSimen Heggestøyl <simen@e5r.no>
Sat, 14 Oct 2017 21:46:17 +0000 (23:46 +0200)
committerBoris Bobrov <breton@cynicmansion.ru>
Mon, 16 Oct 2017 15:21:28 +0000 (18:21 +0300)
Prior to this commit, using a Unicode character in a configuration
string would result in a `UnicodeDecodeError` being raised. Supporting
Unicode characters is especially useful in user-facing configuration
strings, such as `html_title`.

mediagoblin/init/config.py
mediagoblin/tests/fake_carrot_conf_good.ini
mediagoblin/tests/test_config.py

index a9189e8d31e6160334186ee6415f49b6f7454a59..fe4691561e944b69e24416f8be68a81c4145eb4e 100644 (file)
@@ -123,6 +123,7 @@ def read_mediagoblin_config(config_path, config_spec_path=CONFIG_SPEC_PATH):
     config = ConfigObj(
         config_path,
         configspec=config_spec,
+        encoding="UTF8",
         interpolation="ConfigParser")
 
     _setup_defaults(config, config_path, mainconfig_defaults)
index 1377907b92f69005f7da66c8e01e6219651973a5..8dc32525e5ca4bd3b7e82b65655dc38ce1215f39 100644 (file)
@@ -7,7 +7,7 @@ num_carrots = 88
 encouragement_phrase = "I'd love it if you eat your carrots!"
 
 # Something extra!
-blah_blah = "blah!"
+blah_blah = "blæh!"
 
 [celery]
 EAT_CELERY_WITH_CARROTS = False
index b13adae6147cbbcce2fcdb05fbd5637b005633ca..c352741803fa1449e1b5472cbd2d15b11c02f246 100644 (file)
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+#
 # GNU MediaGoblin -- federated, autonomous media hosting
 # Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
 #
@@ -47,7 +49,7 @@ def test_read_mediagoblin_config():
     assert this_conf['carrotapp']['num_carrots'] == 88
     assert this_conf['carrotapp']['encouragement_phrase'] == \
         "I'd love it if you eat your carrots!"
-    assert this_conf['carrotapp']['blah_blah'] == "blah!"
+    assert this_conf['carrotapp']['blah_blah'] == u"blæh!"
     assert this_conf['celery']['EAT_CELERY_WITH_CARROTS'] == False
 
     # A bad file