Browse Source

Fixed a bug in Luminotes Desktop in which a backslash within a note was duplicated each time the note was saved.

Dan Helfman 9 years ago
parent
commit
d37422b592
3 changed files with 59 additions and 10 deletions
  1. 2
    0
      NEWS
  2. 19
    10
      controller/Database.py
  3. 38
    0
      controller/test/Test_notebooks.py

+ 2
- 0
NEWS View File

@@ -3,6 +3,8 @@
3 3
  * Added a "start a new discussion" link to each discussion forum page.
4 4
  * Updated Luminotes Server INSTALL file with instructions for setting the
5 5
    http_url configuration setting.
6
+ * Fixed a bug in Luminotes Desktop in which a backslash within a note was
7
+   duplicated each time the note was saved.
6 8
  * Fixed a bug in which special characters in a customer's name prevented
7 9
    PayPal payments from going through properly.
8 10
 

+ 19
- 10
controller/Database.py View File

@@ -174,6 +174,15 @@ class Database( object ):
174 174
     except ImportError:
175 175
       return None
176 176
 
177
+  def unescape( self, sql_command ):
178
+    """
179
+    For backends that don't treat backslashes specially, un-double all backslashes in the given
180
+    sql_command.
181
+    """
182
+    if self.__backend == Persistent.SQLITE_BACKEND:
183
+      return sql_command.replace( "\\\\", "\\" )
184
+    return sql_command
185
+
177 186
   @synchronized
178 187
   def save( self, obj, commit = True ):
179 188
     """
@@ -187,11 +196,11 @@ class Database( object ):
187 196
     connection = self.get_connection()
188 197
     cursor = connection.cursor()
189 198
 
190
-    cursor.execute( obj.sql_exists() )
199
+    cursor.execute( self.unescape( obj.sql_exists() ) )
191 200
     if cursor.fetchone():
192
-      cursor.execute( obj.sql_update() )
201
+      cursor.execute( self.unescape( obj.sql_update() ) )
193 202
     else:
194
-      cursor.execute( obj.sql_create() )
203
+      cursor.execute( self.unescape( obj.sql_create() ) )
195 204
 
196 205
     if isinstance( obj, self.CLASSES_NOT_TO_CACHE ):
197 206
       cache = None
@@ -285,7 +294,7 @@ class Database( object ):
285 294
     connection = self.get_connection()
286 295
     cursor = connection.cursor()
287 296
 
288
-    cursor.execute( sql_command )
297
+    cursor.execute( self.unescape( sql_command ) )
289 298
 
290 299
     row = self.__row_to_unicode( cursor.fetchone() )
291 300
     if not row:
@@ -317,7 +326,7 @@ class Database( object ):
317 326
     connection = self.get_connection()
318 327
     cursor = connection.cursor()
319 328
 
320
-    cursor.execute( sql_command )
329
+    cursor.execute( self.unescape( sql_command ) )
321 330
 
322 331
     objects = []
323 332
     row = self.__row_to_unicode( cursor.fetchone() )
@@ -352,7 +361,7 @@ class Database( object ):
352 361
     connection = self.get_connection()
353 362
     cursor = connection.cursor()
354 363
 
355
-    cursor.execute( sql_command )
364
+    cursor.execute( self.unescape( sql_command ) )
356 365
 
357 366
     if commit:
358 367
       connection.commit()
@@ -373,7 +382,7 @@ class Database( object ):
373 382
     if self.__backend == Persistent.SQLITE_BACKEND:
374 383
       cursor.executescript( sql_commands )
375 384
     else:
376
-      cursor.execute( sql_commands )
385
+      cursor.execute( self.unescape( sql_commands ) )
377 386
 
378 387
     if commit:
379 388
       connection.commit()
@@ -430,15 +439,15 @@ class Database( object ):
430 439
     # generate a random id, but on the off-chance that it collides with something else already in
431 440
     # the database, try again
432 441
     next_id = Database.generate_id()
433
-    cursor.execute( Object_type.sql_id_exists( next_id ) )
442
+    cursor.execute( self.unescape( Object_type.sql_id_exists( next_id ) ) )
434 443
 
435 444
     while cursor.fetchone() is not None:
436 445
       next_id = Database.generate_id()
437
-      cursor.execute( Object_type.sql_id_exists( next_id ) )
446
+      cursor.execute( self.unescape( Object_type.sql_id_exists( next_id ) ) )
438 447
 
439 448
     # save a new object with the next_id to the database
440 449
     obj = Object_type( next_id )
441
-    cursor.execute( obj.sql_create() )
450
+    cursor.execute( self.unescape( obj.sql_create() ) )
442 451
 
443 452
     if commit:
444 453
       connection.commit()

+ 38
- 0
controller/test/Test_notebooks.py View File

@@ -3363,6 +3363,44 @@ class Test_notebooks( Test_controller ):
3363 3363
     assert note.contents == contents + " bar"
3364 3364
     assert note.user_id == self.user.object_id
3365 3365
 
3366
+  def test_save_new_note_with_backslashes( self ):
3367
+    self.login()
3368
+
3369
+    # save a completely new note
3370
+    contents = r"<h3>newest title</h3>c:\windows\foo\bar\baz.exe"
3371
+    new_note = Note.create( "55", contents )
3372
+    previous_revision = new_note.revision
3373
+    result = self.http_post( "/notebooks/save_note/", dict(
3374
+      notebook_id = self.notebook.object_id,
3375
+      note_id = new_note.object_id,
3376
+      contents = new_note.contents,
3377
+      startup = False,
3378
+      previous_revision = None,
3379
+    ), session_id = self.session_id )
3380
+
3381
+    assert result[ "new_revision" ]
3382
+    assert result[ "new_revision" ] != previous_revision
3383
+    assert result[ "new_revision" ].user_id == self.user.object_id
3384
+    assert result[ "new_revision" ].username == self.username
3385
+    assert result[ "previous_revision" ] == None
3386
+    user = self.database.load( User, self.user.object_id )
3387
+    assert user.storage_bytes > 0
3388
+    assert result[ "storage_bytes" ] == user.storage_bytes
3389
+    assert result[ "rank" ] == 0.0
3390
+
3391
+    # make sure the new title is now loadable
3392
+    result = self.http_post( "/notebooks/load_note_by_title/", dict(
3393
+      notebook_id = self.notebook.object_id,
3394
+      note_title = new_note.title,
3395
+    ), session_id = self.session_id )
3396
+
3397
+    note = result[ "note" ]
3398
+
3399
+    assert note.object_id == new_note.object_id
3400
+    assert note.title == new_note.title
3401
+    assert note.contents == contents
3402
+    assert note.user_id == self.user.object_id
3403
+
3366 3404
   def test_save_two_new_notes( self, startup = False ):
3367 3405
     self.login()
3368 3406
 

Loading…
Cancel
Save