Skip to content

Commit

Permalink
Fix error uploading spectrum files with non-ISO-8859-1 code points in…
Browse files Browse the repository at this point in the history
… the filename.

When the user drag-n-dropped a  file onto InterSpec, a JS exception would be thrown when setting the "X-File-Name" header, if the filename contained a non-ISO-8859-1 code point (ex. IPC_ӨФфФЙжѿ_1.n42).
Now URI encodes filename to put in the header, and URI-decodes in the C++.
  • Loading branch information
wcjohns committed Dec 15, 2023
1 parent 0f20ea7 commit e7b014f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions js/InterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ function()
xhr.setRequestHeader("Content-type", "application/x-spectrum");
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-File-Name", file.name);

// Filename may have non-ISO-8859-1 code points, so we need to URI encode it
xhr.setRequestHeader("X-File-Name", encodeURIComponent(file.name));

//#if( BUILD_AS_ELECTRON_APP ) //C++ preprocessors dont look to work here...
if( lookForPath && (typeof file.path === "string") && (file.path.length > 2) && !file.path.toLowerCase().includes('fake') ) {
Expand Down
4 changes: 3 additions & 1 deletion src/FileDragUploadResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ void FileDragUploadResource::handleRequest( const Http::Request& request,
{
spool_file << request.in().rdbuf();
spool_file.close();
const string userName = request.headerValue( "X-File-Name" );
const string userNameEncoded = request.headerValue( "X-File-Name" );
const string userName = Wt::Utils::urlDecode(userNameEncoded);

cout << "userNameEncoded='" << userNameEncoded << "' --> userName='" << userName << "'" << endl;
//cerr << "\n\n\nuserName = '" << userName << "'\n\n" << endl;

auto app = WApplication::instance();
Expand Down

0 comments on commit e7b014f

Please sign in to comment.