Changed controller.Files.purged_unused() to support file links with rel="nofollow", thereby fixing a bug that purged all uploaded files!
This commit is contained in:
parent
5f42cb2dd1
commit
725dbcdcb7
|
@ -239,7 +239,7 @@ cherrypy._cpcgifs.FieldStorage = FieldStorage
|
||||||
|
|
||||||
|
|
||||||
class Files( object ):
|
class Files( object ):
|
||||||
FILE_LINK_PATTERN = re.compile( u'<a\s+href="[^"]*/files/download\?file_id=([^"&]+)(&[^"]*)?">(<img )?[^<]+</a>', re.IGNORECASE )
|
FILE_LINK_PATTERN = re.compile( u'<a\s+href="[^"]*/files/download\?file_id=([^"&]+)(&[^"]*)?"[^>]*>(<img )?[^<]+</a>', re.IGNORECASE )
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Controller for dealing with uploaded files, corresponding to the "/files" URL.
|
Controller for dealing with uploaded files, corresponding to the "/files" URL.
|
||||||
|
|
|
@ -2530,6 +2530,33 @@ class Test_files( Test_controller ):
|
||||||
assert db_file.filename == self.filename
|
assert db_file.filename == self.filename
|
||||||
assert Upload_file.exists( self.file_id )
|
assert Upload_file.exists( self.file_id )
|
||||||
|
|
||||||
|
def test_purge_unused_keep_file_with_nofollow( self ):
|
||||||
|
self.login()
|
||||||
|
|
||||||
|
self.http_upload(
|
||||||
|
"/files/upload?file_id=%s" % self.file_id,
|
||||||
|
dict(
|
||||||
|
notebook_id = self.notebook.object_id,
|
||||||
|
note_id = self.note.object_id,
|
||||||
|
),
|
||||||
|
filename = self.filename,
|
||||||
|
file_data = self.file_data,
|
||||||
|
content_type = self.content_type,
|
||||||
|
session_id = self.session_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.note.contents = '<a href="/files/download?file_id=%s" rel="nofollow">file link</a>' % self.file_id
|
||||||
|
self.database.save( self.note )
|
||||||
|
|
||||||
|
# the file is linked to from the note's contents, so this should not delete it
|
||||||
|
cherrypy.root.files.purge_unused( self.note )
|
||||||
|
|
||||||
|
db_file = self.database.load( File, self.file_id )
|
||||||
|
assert db_file
|
||||||
|
assert db_file.object_id == self.file_id
|
||||||
|
assert db_file.filename == self.filename
|
||||||
|
assert Upload_file.exists( self.file_id )
|
||||||
|
|
||||||
def test_purge_unused_keep_image_file( self ):
|
def test_purge_unused_keep_image_file( self ):
|
||||||
self.login()
|
self.login()
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user