Skip to content

Commit

Permalink
Use UTF-8 instead of Latin-1
Browse files Browse the repository at this point in the history
This decoding happens when a non-unicode string is rendered in
a DTML template.

The decoding happens in 'join_unicode' which takes no arguments. But a
better fix for this would perhaps be to make that function take an encoding
argument (or boolean keyword argument to enable UTF-8).

However, backwards compatibility here seems rather pointless.
  • Loading branch information
malthe authored and Michael Howitz committed Jun 20, 2018
1 parent fd562ea commit cd6f23f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.13.5 (unreleased)
-------------------

- Use 'utf-8' to decode non-unicode strings instead of 'latin-1'.

2.13.4 (2017-02-15)
-------------------
Expand Down
2 changes: 1 addition & 1 deletion src/DocumentTemplate/cDocumentTemplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ _join_unicode(PyObject *prejoin)
PyObject *item = PyList_GetItem(list,i);
if(PyString_Check(item))
{
PyObject *unicode = PyUnicode_DecodeLatin1(PyString_AsString(item),PyString_Size(item),NULL);
PyObject *unicode = PyUnicode_DecodeUTF8(PyString_AsString(item),PyString_Size(item),NULL);
if(unicode)
{
PyList_SetItem(list,i,unicode);
Expand Down
8 changes: 4 additions & 4 deletions src/DocumentTemplate/tests/testDTMLUnicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,25 @@ def testAB(self):
def testUB(self):
html=self.doc_class('<dtml-var a><dtml-var b>')
expected = u'hello\xc8'
res = html(a=u'hello',b=chr(200))
res = html(a=u'hello',b='\xc3\x88')
assert res == expected, `res`

def testUB2(self):
html=self.doc_class('<dtml-var a><dtml-var b>')
expected = u'\u07d0\xc8'
res = html(a=unichr(2000),b=chr(200))
res = html(a=unichr(2000),b='\xc3\x88')
assert res == expected, `res`

def testUnicodeStr(self):
html=self.doc_class('<dtml-var a><dtml-var b>')
expected = u'\u07d0\xc8'
res = html(a=force_str(unichr(2000)),b=chr(200))
res = html(a=force_str(unichr(2000)),b='\xc3\x88')
assert res == expected, `res`

def testUqB(self):
html=self.doc_class('<dtml-var a html_quote><dtml-var b>')
expected = u'he&gt;llo\xc8'
res = html(a=u'he>llo',b=chr(200))
res = html(a=u'he>llo',b='\xc3\x88')
assert res == expected, `res`

def testSize(self):
Expand Down

0 comments on commit cd6f23f

Please sign in to comment.