Skip to content

Commit

Permalink
Fix handling of encoding for xml configs. (#77)
Browse files Browse the repository at this point in the history
* Use current Zope release versions.
* Actually test with different encoding than default_encoding.
  • Loading branch information
sallner authored and Michael Howitz committed Nov 22, 2018
1 parent 32742fc commit 5a0494c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ New features:

Bug fixes:

- *add item here*
- Convert input from xml configuration with correct encoding before passing to
type_converter.
(`#77 <https://github.com/zopefoundation/Products.GenericSetup/pull/77>`_)
[sallner]


2.0b3 (2018-11-07)
Expand Down
4 changes: 4 additions & 0 deletions Products/GenericSetup/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ def test__initProperties_normal_iso_8859_1(self):
helpers = self._makeOne()
obj = self._getReal(helpers.context)
node = _getDocumentElement(_NORMAL_PROPERTY_EXPORT_ISO_8859_1)
# *sigh* The base class does not respect the encoding specified in the
# xml, so we have to be explicit here. In the real world it is in
# responsibility of the subclass.
helpers._encoding = 'iso-8859-1'
helpers._initProperties(node)
self.assertEqual(type(obj.foo_int), int)
self.assertEqual(type(obj.foo_string), str)
Expand Down
2 changes: 1 addition & 1 deletion Products/GenericSetup/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def markupComparison(self, lines):
elif line.startswith('-'):
result.append(('diff-removed', line))

elif line == '\ No newline at end of file':
elif line == r'\ No newline at end of file':
result.append(('diff-context', line))

else:
Expand Down
7 changes: 4 additions & 3 deletions Products/GenericSetup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,11 @@ def _initProperties(self, node):
# The type_converters use the ZPublisher default_encoding
# for decoding bytes!
if self._encoding.lower() != default_encoding:
u_prop_value = prop_value.decode(self._encoding)
prop_value = u_prop_value.encode(default_encoding)
if isinstance(prop_value, six.binary_type):
u_prop_value = prop_value.decode(self._encoding)
prop_value = u_prop_value.encode(default_encoding)
prop_value = type_converters[prop_type](prop_value)
if six.PY2:
if isinstance(prop_value, six.binary_type):
u_prop_value = prop_value.decode(default_encoding)
prop_value = u_prop_value.encode(self._encoding)
else:
Expand Down
2 changes: 1 addition & 1 deletion buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[buildout]
extends = https://zopefoundation.github.io/Zope/releases/4.0b6/versions-prod.cfg
extends = https://zopefoundation.github.io/Zope/releases/4.0b7/versions-prod.cfg
develop = .
parts =
test
Expand Down

0 comments on commit 5a0494c

Please sign in to comment.