From 91f4280b3e378ccf05177844f491118021e3cb74 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 25 Mar 2015 23:37:40 +0100 Subject: [PATCH] nopaste: Fix uploading content with backslashes --- webapp/backend/nopaste.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webapp/backend/nopaste.py b/webapp/backend/nopaste.py index 7eb69d0..4f87733 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), \ -- 2.39.2