在作为 HTTP/1.1 标准的rfc2616中,带引号的字符串定义如下。
quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
quoted-pair = "\" CHAR
CHAR = <any US-ASCII character (octets 0 - 127)>
qdtext = <any TEXT except <">>
TEXT = <any OCTET except CTLs, but including LWS>
有了这个定义, "" 似乎是一个 TEXT,因此<">\<">
(quote, backslash, quote) 似乎是一个有效的带引号的字符串。但这与正确使用反斜杠作为转义字符相矛盾,甚至可能导致无法明确地确定引用字符串的结尾。我的错误在哪里?
RFC 还指出
LWS = [CRLF] 1*( SP | HT )
All linear
white space, including folding, has the same semantics as SP. A
recipient MAY replace any linear white space with a single SP before
interpreting the field value or forwarding the message downstream.
我已经阅读了即使带引号的字符串中的 LWS 也可以被 SP 替换的解释。如果我从字面上理解 RFC,那就是它所说的。我对此感到困惑,因为这意味着引用的字符串“”、“\n”、“\n\t \t \t”……都是一样的。那些引用的字符串真的不能在语义上区分吗?