Using TWebRequest (isapi application) to receive a POST/multipart/form-data request with one or more files.
When the filename contains a % symbol (for example, "Sales % by date.doc") an exception is generated when the request is parsed (e.g. using request.contentfields.count, request.extractcontentfields()). The exception is
Invalid URL encoded character (% b) at position xx
or similar (depending on the filename).
I've tried intercepting the file name and correcting (for example "Sales %25 by date.doc"), but I'm not able to set Request.Content and parse.
I've tried intercepting and renaming the file before the client side (browser) form is submitted, but the browser is restricting that for an <input type=file> tag.
Is there a way of changing how the filename would be decoded? Is this a bug that is fixed in 11? Any other tips/tricks would be appreciated.
I was able to resolve the issue by going to the source code for TWebRequest in Web.HTTPApp.pas and modify the code in the ExtractHeaderFields procedure. In that procedure, there is an untrapped instance of TNetEncoding.URL.Decode(). The behavior I was looking for: if there is an exception in the Decode operation, I want it to exit gracefully without modifying the string. So, the original code was:
I modified to:
That resolved my issue.