Hello,

If a filename with a special character is passed to 
WResource::suggestFileName(), browser detects the name incorrectly.  In 
the following example program, a filename "A B.txt" with a space character 
is used.  When the link is clicked in Firefox 3.6.12, it suggests filename 
"A".


#include <Wt/WAnchor>
#include <Wt/WApplication>
#include <Wt/WFileResource>
#include <Wt/WText>

static Wt::WApplication* createApplication(Wt::WEnvironment const& environment)
{
  Wt::WApplication* application = new Wt::WApplication(environment);

  Wt::WResource* resource = new Wt::WFileResource( "./docroot/foo.txt", 
application );
  resource->suggestFileName( "A B.txt" );
  Wt::WAnchor* anchor = new Wt::WAnchor(resource);
  new Wt::WText( Wt::WString( "link" ), anchor );

  application->root()->addWidget(anchor);

  return application;
}

int main(int argc, char* argv[])
{
  return Wt::WRun(argc, argv, &createApplication);
}


Maybe there is a syntax error in constructing the HTTP response?  If I add 
quotes around the filename in the response, Firefox determines the 
filename correctly.  Here is a patch to add the quotes.  Probably more 
changes are needed: the filename itself may contain quotes for example.


>From 46ad90d4b758851d8f558d506bf58b7b89dd002f Mon Sep 17 00:00:00 2001
From: Markus Rinne <[email protected]>
Date: Mon, 29 Nov 2010 16:45:04 +0200
Subject: [PATCH] Put resource filename in quotes.

Quotes are needed if the filename contains spaces or some other
special characters.
---
 src/Wt/WResource.C |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/Wt/WResource.C b/src/Wt/WResource.C
index 576ac77..e888e01 100644
--- a/src/Wt/WResource.C
+++ b/src/Wt/WResource.C
@@ -115,7 +115,7 @@ void WResource::handle(WebRequest *webRequest, WebResponse 
*webResponse,
 
   if (!continuation && !suggestedFileName_.empty())
     response.addHeader("Content-Disposition",
-                      "attachment;filename=" + suggestedFileName_);
+                      "attachment;filename=\"" + suggestedFileName_ + "\"");
 
   handleRequest(request, response);
 
-- 
1.7.3.1


------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to