Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 699

RegExp to validate an HTTP header value

$
0
0

I'm sending a custom header to my back-end:

var oXhr = new XMLHttpRequest;oXhr.setRequestHeader("X-File-Name", fileName);

But if fileName contains accents for example, I get:

SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest':'é - December 3rd, 2015.pdf' is not a valid HTTP header field value.

I have a hard time understanding the doc...

edit:

I realized that even though it does look like an accent, it's something different. It is the character: ́

It behaves strangely (ascii code 769), it confuses my browser console and even phpStorm. It comes on top of the very next character, no matter what, even when pasted (try it). The problem is that the content of this header value is a file name chosen by user from a file picker, and this file name contains this character. What would be the best approach to filter this kind of incident?


Viewing all articles
Browse latest Browse all 699

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>