From: Michael Tremer Date: Wed, 25 Mar 2015 22:37:40 +0000 (+0100) Subject: nopaste: Fix uploading content with backslashes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91f4280b3e378ccf05177844f491118021e3cb74;p=ipfire.org.git nopaste: Fix uploading content with backslashes --- diff --git a/webapp/backend/nopaste.py b/webapp/backend/nopaste.py index 7eb69d0d..4f877330 100644 --- a/webapp/backend/nopaste.py +++ b/webapp/backend/nopaste.py @@ -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), \