For an Internet MIME media type (RFC 6838), a parameter may be quoted (RFC 2045). For example the following represents a value of foobar
:
text/plain;test="foobar"
But am I allowed to include an escaped quote inside the quoted parameter? The following would represent a value of foo"bar
:
text/plain;test="foo\"bar"
If so, then what about an escaped escape character? The following would represent a value of foo\bar
:
text/plain;test="foo\\bar"
What about arbitrarily escaped characters? The following would represent a value of fooxbar
, because the escape sequence \x
would simply represent x
:
text/plain;test="foo\xbar"
And just as importantly, which standard(s) defines this?
I would guess that at least escaped quotes and escaped backslashes are allowed, but I'm having trouble finding where this is specified.
I don't have a complete answer yet, but I know that the WhatWG says that a MIME type parameter value must contain HTTP quoted-string token code points. While it provides its own definitions, the WhatWG refers to RFC 7230 § 3.2.6. Field Value Components, which allows almost any escaping:
quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
qdtext = HTAB / SP /%x21 / %x23-5B / %x5D-7E / obs-text
obs-text = %x80-FF
quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
However it notes:
A sender SHOULD NOT generate a quoted-pair in a quoted-string except where necessary to quote DQUOTE and backslash octets occurring within that string.
Note also that RFC 5322 § 3.2.1. Quoted characters also has some rules. RFC 6838 governing media types mentions RFC 6532 § 3.2. Syntax Extensions to RFC 5322, although not clearly in the context of parameter values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With