]> git.ipfire.org Git - ipfire.org.git/commitdiff
nopaste: Fix uploading content with backslashes
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Mar 2015 22:37:40 +0000 (23:37 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Mar 2015 22:37:40 +0000 (23:37 +0100)
webapp/backend/nopaste.py

index 7eb69d0dd5f392d36d8d4a6b6b4ca0e47676658b..4f877330cf25fd9d3c248b94e0a1139054fe2b02 100644 (file)
@@ -3,13 +3,18 @@
 from misc import Object
 
 class Nopaste(Object):
-       def create(self, subject, content, expires=None, account=None, address=None):
+       def create(self, subject, content, type="text", expires=None, account=None, address=None):
                self._cleanup_database()
 
                uid = None
                if account:
                        uid = account.uid
 
+               # Escape any backslashes. PostgreSQL tends to think that they lead octal
+               # values or something that confuses the convertion from text to bytea.
+               if type == "text":
+                       content = content.replace("\\", "\\\\")
+
                # http://blog.00null.net/easily-generating-random-strings-in-postgresql/
                res = self.db.get("INSERT INTO nopaste(uuid, subject, content, time_expires, address, uid) \
                        VALUES(random_slug(), %s, %s, (CASE WHEN %s = 0 THEN NULL ELSE NOW() + INTERVAL '%s seconds' END), \