From 4d24914496584f829cfb272da40b8854b0fb16cd Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 29 Sep 2008 23:35:45 -0700 Subject: [PATCH] Leading/trailing spaces and newlines in note titles and contents are now stripped out when exporting to CSV. --- NEWS | 2 ++ controller/Notebooks.py | 4 ++-- controller/test/Test_notebooks.py | 10 ++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index ab9f980..2f49be3 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ * Leading/trailing spaces in note titles are now ignored when making links to such notes. This means that creating a link titled "my note" to a note called "my note " now works properly. + * Leading/trailing spaces and newlines in note titles and contents are now + stripped out when exporting to CSV. * Fixed a bug in which clicking the "export" link when the current note was unsaved did not open the export pulldown. diff --git a/controller/Notebooks.py b/controller/Notebooks.py index 16a72c1..f7947b4 100644 --- a/controller/Notebooks.py +++ b/controller/Notebooks.py @@ -1263,8 +1263,8 @@ class Notebooks( object ): user = self.__database.load( User, note.user_id ) writer.writerow( ( - note.contents and note.contents.encode( "utf8" ) or None, - note.title and note.title.encode( "utf8" ) or None, + note.contents and note.contents.strip().encode( "utf8" ) or None, + note.title and note.title.strip().encode( "utf8" ) or None, note.object_id, note.startup and 1 or 0, note.user_id and user and user.username and user.username.encode( "utf8" ) or u"", diff --git a/controller/test/Test_notebooks.py b/controller/test/Test_notebooks.py index 33bec8f..88a5eeb 100644 --- a/controller/test/Test_notebooks.py +++ b/controller/test/Test_notebooks.py @@ -3619,10 +3619,10 @@ class Test_notebooks( Test_controller ): db_note = self.database.load( Note, note_id ) assert db_note - assert contents.decode( "utf8" ) == db_note.contents + assert contents.decode( "utf8" ) == db_note.contents.strip() if db_note.title: - assert title.decode( "utf8" ) == db_note.title + assert title.decode( "utf8" ) == db_note.title.strip() else: assert not title @@ -3639,6 +3639,12 @@ class Test_notebooks( Test_controller ): def test_export_csv_without_note_title( self ): self.test_export_csv( note_contents = u"there's no title" ) + def test_export_csv_with_trailing_newline_in_title( self ): + self.test_export_csv( note_contents = u"

blah\n

foo" ) + + def test_export_csv_with_trailing_newline_in_contents( self ): + self.test_export_csv( note_contents = u"

blah

foo\n" ) + def test_export_csv_with_blank_username( self ): self.user._User__username = None self.database.save( self.user )