hgweb: Quote filenames when downloading raw files.
authorThomas Arendsen Hein <thomas@intevation.de>
Sat, 16 Feb 2008 18:12:30 +0100
changeset 6137 1c0e7afe824a
parent 6136 acfb9fa494e2
child 6138 09847b90beae
hgweb: Quote filenames when downloading raw files.
mercurial/hgweb/request.py
tests/test-webraw
tests/test-webraw.out
--- a/mercurial/hgweb/request.py	Sat Feb 16 17:51:30 2008 +0100
+++ b/mercurial/hgweb/request.py	Sat Feb 16 18:12:30 2008 +0100
@@ -85,8 +85,10 @@
         if type is not None:
             headers.append(('Content-Type', type))
         if filename:
+            filename = (filename.split('/')[-1]
+                        .replace('\\', '\\\\').replace('"', '\\"'))
             headers.append(('Content-Disposition',
-                            'inline; filename=%s' % filename.split('/')[-1]))
+                            'inline; filename="%s"' % filename))
         if length:
             headers.append(('Content-Length', str(length)))
         self.header(headers)
--- a/tests/test-webraw	Sat Feb 16 17:51:30 2008 +0100
+++ b/tests/test-webraw	Sat Feb 16 18:12:30 2008 +0100
@@ -3,17 +3,17 @@
 hg init test
 cd test
 mkdir sub
-cat >sub/sometext.txt <<ENDSOME
+cat >'sub/some "text".txt' <<ENDSOME
 This is just some random text
 that will go inside the file and take a few lines.
 It is very boring to read, but computers don't
 care about things like that.
 ENDSOME
-hg add sub/sometext.txt
+hg add 'sub/some "text".txt'
 hg commit -d "1 0" -m "Just some text"
 hg serve -p $HGPORT -A access.log -E error.log -d --pid-file=hg.pid
 cat hg.pid >> $DAEMON_PIDS
-("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/?f=37afcac6d393;file=sub/sometext.txt;style=raw' content-type content-length content-disposition) >getoutput.txt &
+("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/?f=a23bf1310f6e;file=sub/some%20%22text%22.txt;style=raw' content-type content-length content-disposition) >getoutput.txt &
 
 sleep 5
 kill `cat hg.pid`
--- a/tests/test-webraw.out	Sat Feb 16 17:51:30 2008 +0100
+++ b/tests/test-webraw.out	Sat Feb 16 18:12:30 2008 +0100
@@ -1,10 +1,10 @@
 200 Script output follows
 content-type: text/plain
 content-length: 157
-content-disposition: inline; filename=sometext.txt
+content-disposition: inline; filename="some \"text\".txt"
 
 This is just some random text
 that will go inside the file and take a few lines.
 It is very boring to read, but computers don't
 care about things like that.
-host - - [date] "GET /?f=37afcac6d393;file=sub/sometext.txt;style=raw HTTP/1.1" 200 -
+host - - [date] "GET /?f=a23bf1310f6e;file=sub/some%20%22text%22.txt;style=raw HTTP/1.1" 200 -