Browse Source

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

Dan Helfman 10 years ago
parent
commit
f2b88441ee
5 changed files with 87 additions and 6 deletions
  1. 5
    0
      NEWS
  2. 8
    2
      controller/Html_nuker.py
  3. 1
    1
      controller/Notebooks.py
  4. 19
    3
      controller/test/Test_notebooks.py
  5. 54
    0
      model/test/Test_note.py

+ 5
- 0
NEWS View File

@@ -1,3 +1,8 @@
1
+1.5.2: 
2
+ * Leading/trailing spaces in note titles are now ignored when making links
3
+   to such notes. This means that creating a link titled "my note" to a note
4
+   called "my note  " now works properly.
5
+
1 6
 1.5.1: September 28, 2008
2 7
  * Implemented CSV exporting, so now you can export all of your notes to a
3 8
    CSV spreadsheet file. This currently doesn't include revision history or

+ 8
- 2
controller/Html_nuker.py View File

@@ -25,13 +25,17 @@ class Html_nuker( HTMLParser ):
25 25
 
26 26
   def handle_entityref( self, ref ):
27 27
     if self.allow_refs:
28
-      self.result.append( "&%s;" % ref )
28
+      if ref == "nbsp":
29
+        self.result.append( " " )
30
+      else:
31
+        self.result.append( "&%s;" % ref )
29 32
     else:
30 33
       self.result.append( {
31 34
         "amp": "&",
32 35
         "lt": "<",
33 36
         "gt": ">",
34 37
         "quot": '"',
38
+        "nbsp": " ",
35 39
       }.get ( ref, "" ) )
36 40
 
37 41
   def handle_comment( self, comment ):
@@ -60,4 +64,6 @@ class Html_nuker( HTMLParser ):
60 64
     self.result = []
61 65
     self.feed( rawstring )
62 66
 
63
-    return u"".join( self.result )
67
+    result = u"".join( self.result ).strip()
68
+
69
+    return result

+ 1
- 1
controller/Notebooks.py View File

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

+ 19
- 3
controller/test/Test_notebooks.py View File

@@ -1204,6 +1204,22 @@ class Test_notebooks( Test_controller ):
1204 1204
     user = self.database.load( User, self.user.object_id )
1205 1205
     assert user.storage_bytes == 0
1206 1206
 
1207
+  def test_load_note_by_title_with_trailing_whitespace( self ):
1208
+    self.login()
1209
+
1210
+    result = self.http_post( "/notebooks/load_note_by_title/", dict(
1211
+      notebook_id = self.notebook.object_id,
1212
+      note_title = "%s    " % self.note.title,
1213
+    ), session_id = self.session_id )
1214
+
1215
+    note = result[ "note" ]
1216
+
1217
+    assert note.object_id == self.note.object_id
1218
+    assert note.title == self.note.title
1219
+    assert note.contents == self.note.contents
1220
+    user = self.database.load( User, self.user.object_id )
1221
+    assert user.storage_bytes == 0
1222
+
1207 1223
   def test_load_note_by_title_case_insensitive( self ):
1208 1224
     self.login()
1209 1225
 
@@ -4711,7 +4727,7 @@ class Test_notebooks( Test_controller ):
4711 4727
 
4712 4728
     self.__assert_imported_notebook( expected_notes, result )
4713 4729
 
4714
-  def test_import_csv_html_title( self ):
4730
+  def test_import_csv_html_in_plaintext_title( self ):
4715 4731
     self.login()
4716 4732
 
4717 4733
     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 ):
5040 5056
     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'
5041 5057
     expected_notes = [
5042 5058
       ( "blah and stuff", "3.3" ), # ( title, contents )
5043
-      ( "wh&nbsp;ee", "hmm\nfoo" ),
5059
+      ( "wh ee", "hmm\nfoo" ),
5044 5060
       ( "4", "5" ),
5045 5061
     ]
5046 5062
 
@@ -5103,7 +5119,7 @@ class Test_notebooks( Test_controller ):
5103 5119
 
5104 5120
     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'
5105 5121
     expected_notes = [
5106
-      ( "3.3 &nbsp;", "3.<b>3 &nbsp;</b>" ), # ( title, contents )
5122
+      ( "3.3", "3.<b>3 &nbsp;</b>" ), # ( title, contents )
5107 5123
       ( "hmm", "hmm\n<i>foo</i>" ),
5108 5124
       ( "5", "5" ),
5109 5125
     ]

+ 54
- 0
model/test/Test_note.py View File

@@ -49,6 +49,60 @@ class Test_note( object ):
49 49
     assert self.note.user_id == self.user_id
50 50
     assert self.note.creation == self.creation
51 51
 
52
+  def test_set_contents_with_title_with_trailing_whitespace( self ):
53
+    new_title = u"new title"
54
+    new_contents = u"<h3>%s  </h3>new blah" % new_title
55
+    previous_revision = self.note.revision
56
+
57
+    self.note.contents = new_contents
58
+
59
+    assert self.note.revision > previous_revision
60
+    assert self.note.contents == new_contents
61
+    assert self.note.summary == None
62
+    assert self.note.title == new_title
63
+    assert self.note.notebook_id == self.notebook_id
64
+    assert self.note.startup == self.startup
65
+    assert self.note.deleted_from_id == None
66
+    assert self.note.rank == self.rank
67
+    assert self.note.user_id == self.user_id
68
+    assert self.note.creation == self.creation
69
+
70
+  def test_set_contents_with_title_with_trailing_nbsp( self ):
71
+    new_title = u"new title"
72
+    new_contents = u"<h3>%s&nbsp; </h3>new blah" % new_title
73
+    previous_revision = self.note.revision
74
+
75
+    self.note.contents = new_contents
76
+
77
+    assert self.note.revision > previous_revision
78
+    assert self.note.contents == new_contents
79
+    assert self.note.summary == None
80
+    assert self.note.title == new_title
81
+    assert self.note.notebook_id == self.notebook_id
82
+    assert self.note.startup == self.startup
83
+    assert self.note.deleted_from_id == None
84
+    assert self.note.rank == self.rank
85
+    assert self.note.user_id == self.user_id
86
+    assert self.note.creation == self.creation
87
+
88
+  def test_set_contents_with_title_with_internal_nbsp( self ):
89
+    new_title = u"new&nbsp;title"
90
+    new_contents = u"<h3>%s</h3>new blah" % new_title
91
+    previous_revision = self.note.revision
92
+
93
+    self.note.contents = new_contents
94
+
95
+    assert self.note.revision > previous_revision
96
+    assert self.note.contents == new_contents
97
+    assert self.note.summary == None
98
+    assert self.note.title == u"new title"
99
+    assert self.note.notebook_id == self.notebook_id
100
+    assert self.note.startup == self.startup
101
+    assert self.note.deleted_from_id == None
102
+    assert self.note.rank == self.rank
103
+    assert self.note.user_id == self.user_id
104
+    assert self.note.creation == self.creation
105
+
52 106
   def test_set_contents_with_html_title( self ):
53 107
     new_title = u"new title"
54 108
     new_contents = u"<h3>new<br /> title</h3>new blah"

Loading…
Cancel
Save