From 0a39430730b51a3a1416f6cb768c1860bb36a8d6 Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Sat, 25 Aug 2007 12:05:24 -0700
Subject: [PATCH] webish: strip leading/tailing whitespace from user-provided
 filenames, to avoid confusion

---
 src/allmydata/webish.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py
index 633aef7e..d4adacbd 100644
--- a/src/allmydata/webish.py
+++ b/src/allmydata/webish.py
@@ -591,6 +591,8 @@ class POSTHandler(rend.Page):
             req.setResponseCode(http.BAD_REQUEST)
             req.setHeader("content-type", "text/plain")
             return "name= may not contain a slash"
+        if name is not None:
+            name = name.strip()
         # we allow the user to delete an empty-named file, but not to create
         # them, since that's an easy and confusing mistake to make
 
@@ -641,7 +643,11 @@ class POSTHandler(rend.Page):
             d.addCallback(_done)
         elif t == "rename":
             from_name = 'from_name' in req.fields and req.fields["from_name"].value
+            if from_name is not None:
+                from_name = from_name.strip()
             to_name = 'to_name' in req.fields and req.fields["to_name"].value
+            if to_name is not None:
+                to_name = to_name.strip()
             if not from_name or not to_name:
                 raise RuntimeError("rename requires from_name and to_name")
             if not IDirectoryNode.providedBy(self._node):
@@ -667,6 +673,8 @@ class POSTHandler(rend.Page):
         elif t == "upload":
             contents = req.fields["file"]
             name = name or contents.filename
+            if name is not None:
+                name = name.strip()
             if not name:
                 raise RuntimeError("set-uri requires a name")
             uploadable = upload.FileHandle(contents.file)
-- 
2.45.2