witten
/
luminotes
Archived
1
0
Fork 0

Leading/trailing spaces in note titles are now ignored when making links to such notes.

This commit is contained in:
Dan Helfman 2008-09-28 14:48:22 -07:00
parent d62fa9f95a
commit f2b88441ee
5 changed files with 87 additions and 6 deletions

5
NEWS
View File

@ -1,3 +1,8 @@
1.5.2:
* 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.
1.5.1: September 28, 2008
* Implemented CSV exporting, so now you can export all of your notes to a
CSV spreadsheet file. This currently doesn't include revision history or

View File

@ -25,13 +25,17 @@ class Html_nuker( HTMLParser ):
def handle_entityref( self, ref ):
if self.allow_refs:
self.result.append( "&%s;" % ref )
if ref == "nbsp":
self.result.append( " " )
else:
self.result.append( "&%s;" % ref )
else:
self.result.append( {
"amp": "&",
"lt": "<",
"gt": ">",
"quot": '"',
"nbsp": " ",
}.get ( ref, "" ) )
def handle_comment( self, comment ):
@ -60,4 +64,6 @@ class Html_nuker( HTMLParser ):
self.result = []
self.feed( rawstring )
return u"".join( self.result )
result = u"".join( self.result ).strip()
return result

View File

@ -462,7 +462,7 @@ class Notebooks( object ):
return note
# remove all HTML from the contents and also remove the title
summary = Html_nuker().nuke( note.contents ).strip()
summary = Html_nuker().nuke( note.contents )
if note.title and summary.startswith( note.title ):
summary = summary[ len( note.title ) : ]

View File

@ -1204,6 +1204,22 @@ class Test_notebooks( Test_controller ):
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
def test_load_note_by_title_with_trailing_whitespace( self ):
self.login()
result = self.http_post( "/notebooks/load_note_by_title/", dict(
notebook_id = self.notebook.object_id,
note_title = "%s " % self.note.title,
), session_id = self.session_id )
note = result[ "note" ]
assert note.object_id == self.note.object_id
assert note.title == self.note.title
assert note.contents == self.note.contents
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
def test_load_note_by_title_case_insensitive( self ):
self.login()
@ -4711,7 +4727,7 @@ class Test_notebooks( Test_controller ):
self.__assert_imported_notebook( expected_notes, result )
def test_import_csv_html_title( self ):
def test_import_csv_html_in_plaintext_title( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah <i>and</i>&nbsp; stuff<br />",3.3\n"8","whee<p>","hmm\nfoo"\n3,4,5'
@ -5040,7 +5056,7 @@ class Test_notebooks( Test_controller ):
csv_data = '"label 1","label 2","label 3"\n5,"<i>blah</i> and stuff",3.3\n"8","wh&nbsp;ee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "blah and stuff", "3.3" ), # ( title, contents )
( "wh&nbsp;ee", "hmm\nfoo" ),
( "wh ee", "hmm\nfoo" ),
( "4", "5" ),
]
@ -5103,7 +5119,7 @@ class Test_notebooks( Test_controller ):
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","3.<b>3 &nbsp;</b>"\n"8","whee","hmm\n<i>foo</i>"\n3,4,5'
expected_notes = [
( "3.3 &nbsp;", "3.<b>3 &nbsp;</b>" ), # ( title, contents )
( "3.3", "3.<b>3 &nbsp;</b>" ), # ( title, contents )
( "hmm", "hmm\n<i>foo</i>" ),
( "5", "5" ),
]

View File

@ -49,6 +49,60 @@ class Test_note( object ):
assert self.note.user_id == self.user_id
assert self.note.creation == self.creation
def test_set_contents_with_title_with_trailing_whitespace( self ):
new_title = u"new title"
new_contents = u"<h3>%s </h3>new blah" % new_title
previous_revision = self.note.revision
self.note.contents = new_contents
assert self.note.revision > previous_revision
assert self.note.contents == new_contents
assert self.note.summary == None
assert self.note.title == new_title
assert self.note.notebook_id == self.notebook_id
assert self.note.startup == self.startup
assert self.note.deleted_from_id == None
assert self.note.rank == self.rank
assert self.note.user_id == self.user_id
assert self.note.creation == self.creation
def test_set_contents_with_title_with_trailing_nbsp( self ):
new_title = u"new title"
new_contents = u"<h3>%s&nbsp; </h3>new blah" % new_title
previous_revision = self.note.revision
self.note.contents = new_contents
assert self.note.revision > previous_revision
assert self.note.contents == new_contents
assert self.note.summary == None
assert self.note.title == new_title
assert self.note.notebook_id == self.notebook_id
assert self.note.startup == self.startup
assert self.note.deleted_from_id == None
assert self.note.rank == self.rank
assert self.note.user_id == self.user_id
assert self.note.creation == self.creation
def test_set_contents_with_title_with_internal_nbsp( self ):
new_title = u"new&nbsp;title"
new_contents = u"<h3>%s</h3>new blah" % new_title
previous_revision = self.note.revision
self.note.contents = new_contents
assert self.note.revision > previous_revision
assert self.note.contents == new_contents
assert self.note.summary == None
assert self.note.title == u"new title"
assert self.note.notebook_id == self.notebook_id
assert self.note.startup == self.startup
assert self.note.deleted_from_id == None
assert self.note.rank == self.rank
assert self.note.user_id == self.user_id
assert self.note.creation == self.creation
def test_set_contents_with_html_title( self ):
new_title = u"new title"
new_contents = u"<h3>new<br /> title</h3>new blah"