【发布时间】:2011-12-14 18:23:16
【问题描述】:
在 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>
有了这个定义,“”似乎是一个文本,因此<">\<">(引号、反斜杠、引号)似乎是一个有效的带引号的字符串。但这与正确使用反斜杠作为转义字符相矛盾,甚至可能导致无法明确地确定引用字符串的结尾。我的错误在哪里?
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”……都是一样的。那些引用的字符串真的不能在语义上区分吗?
【问题讨论】:
-
有关信息,如果有人查找引用字符串(或其他任何内容)的语法,RFC2616 已被 RFC7230-7235 (source) 废弃,并且包含更正的
quoted-string语法的是RFC7230。