wooster/biplist

Weird encoding issue

0x5e opened this issue · 5 comments

0x5e commented

Hi,
I have a weird encoding trouble using biplist and spend many days to reproduce the problem, here's the test code:

#!/usr/bin/env python
# -*- coding: utf-8 -*

import biplist
import unittest

class TestEncoding(unittest.TestCase):

  def test_encoding(self):
    en = { 'key': 'ON' } # 'ON' => '\x4f\x4e'
    zh = { 'key': u'低' } # '低' => '\u4f4e'

    # Comment the following line, then test succeed.
    biplist.writePlistToString(en)

    zh_plist = biplist.writePlistToString(zh)
    zh2 = biplist.readPlistFromString(zh_plist)
    self.assertDictEqual(zh, zh2)

test case failed if writePlist twice. If I comment biplist.writePlistToString(en), it will success. If I change 'ON' or u'低' to other word, it also success.

0x5e commented
>>> biplist.StringWrapper._StringWrapper__instances
{'ON': <StringWrapper (ascii): ON>, 'key': <StringWrapper (ascii): key>}

the memory leak cause this problem?

It could be. I don't have much time to look into this until next month, unfortunately. :-(

This seems weird:

>>> u'\u4f4e'.encode('utf_16_be')
'ON'
0x5e commented

It's okay, I'm using plutil temporary.
Seems u'\u4f4e' split to '\x4f' , '\x4e'.

0x5e commented

Another workaround is set biplist.StringWrapper._StringWrapper__instances = {} after every writePlist