Skip to content

Commit

Permalink
Decode strings from change objects as if they're utf-8.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris AtLee committed May 10, 2010
1 parent c7fb643 commit 57125af
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
5 changes: 4 additions & 1 deletion buildbot/db/schema/v1.py
Expand Up @@ -259,7 +259,10 @@ def _addChangeToDatabase(self, change, cursor):
# strip None from any of these values, just in case
def remove_none(x):
if x is None: return ""
return x
elif isinstance(x, str):
return x.decode("utf8", "replace")
else:
return x
values = tuple(remove_none(x) for x in
(change.number, change.who,
change.comments, change.isdir,
Expand Down
47 changes: 47 additions & 0 deletions buildbot/test/regressions/test_import_unicode_changes.py
@@ -0,0 +1,47 @@
import os
import shutil
import cPickle

from twisted.trial import unittest

from buildbot.changes.changes import Change

from buildbot.db.schema import manager
from buildbot.db.dbspec import DBSpec
from buildbot.db.connector import DBConnector

class Thing:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)


class TestUnicodeChanges(unittest.TestCase):
def setUp(self):
self.basedir = "UnicodeChanges"
if os.path.exists(self.basedir):
shutil.rmtree(self.basedir)
os.makedirs(self.basedir)
self.db = None

def tearDown(self):
if self.db:
self.db.stop()

def testUnicodeChange(self):
# Create changes.pck
changes = [Change(who=u"Frosty the \N{SNOWMAN}".encode("utf8"),
files=["foo"], comments=u"Frosty the \N{SNOWMAN}".encode("utf8"), branch="b1", revision=12345)]
cPickle.dump(Thing(changes=changes), open(os.path.join(self.basedir, "changes.pck"), "w"))

# Now try the upgrade process, which will import the old changes.
spec = DBSpec.from_url("sqlite:///state.sqlite", self.basedir)

sm = manager.DBSchemaManager(spec, self.basedir)
sm.upgrade()
self.db = DBConnector(spec)
self.db.start()

c = self.db.getChangeNumberedNow(1)

self.assertEquals(c.who, u"Frosty the \N{SNOWMAN}")
self.assertEquals(c.comments, u"Frosty the \N{SNOWMAN}")

0 comments on commit 57125af

Please sign in to comment.