make sure we don't chomp embedded newlines when clearing comments (#722)

This commit is contained in:
Damien Elmes 2013-04-11 14:33:30 +09:00
parent 3be7c998fc
commit a525d3c32c

View File

@ -32,6 +32,7 @@ class TextImporter(NoteImporter):
for row in reader: for row in reader:
row = [unicode(x, "utf-8") for x in row] row = [unicode(x, "utf-8") for x in row]
if len(row) != self.numFields: if len(row) != self.numFields:
if row:
log.append(_( log.append(_(
"'%(row)s' had %(num1)d fields, " "'%(row)s' had %(num1)d fields, "
"expected %(num2)d") % { "expected %(num2)d") % {
@ -65,8 +66,8 @@ class TextImporter(NoteImporter):
if self.data.startswith(codecs.BOM_UTF8): if self.data.startswith(codecs.BOM_UTF8):
self.data = self.data[len(codecs.BOM_UTF8):] self.data = self.data[len(codecs.BOM_UTF8):]
def sub(s): def sub(s):
return re.sub("^\#.*", "", s) return re.sub("^\#.*$", "__comment", s)
self.data = [sub(x)+"\n" for x in self.data.split("\n") if sub(x)] self.data = [sub(x)+"\n" for x in self.data.split("\n") if sub(x) != "__comment"]
if self.data: if self.data:
if self.data[0].startswith("tags:"): if self.data[0].startswith("tags:"):
tags = unicode(self.data[0][5:], "utf8").strip() tags = unicode(self.data[0][5:], "utf8").strip()