Skip to content

Commit 22d0c6b

Browse files
authoredNov 3, 2021
HTTP: Relax pattern for body (#3169)
1 parent b631949 commit 22d0c6b

14 files changed

+182
-15
lines changed
 

‎components/prism-http.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,16 @@
9090

9191
var pattern = suffixTypes[contentType] ? getSuffixPattern(contentType) : contentType;
9292
options[contentType.replace(/\//g, '-')] = {
93-
pattern: RegExp('(content-type:\\s*' + pattern + '(?:(?:\\r\\n?|\\n).+)*)(?:\\r?\\n|\\r){2}[\\s\\S]*', 'i'),
93+
pattern: RegExp(
94+
'(' + /content-type:\s*/.source + pattern + /(?:(?:\r\n?|\n)[\w-].*)*(?:\r(?:\n|(?!\n))|\n)/.source + ')' +
95+
// This is a little interesting:
96+
// The HTTP format spec required 1 empty line before the body to make everything unambiguous.
97+
// However, when writing code by hand (e.g. to display on a website) people can forget about this,
98+
// so we want to be liberal here. We will allow the empty line to be omitted if the first line of
99+
// the body does not start with a [\w-] character (as headers do).
100+
/[^\w-][\s\S]*/.source,
101+
'i'
102+
),
94103
lookbehind: true,
95104
inside: httpLanguages[contentType]
96105
};

‎components/prism-http.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/languages/css+http/css_inclusion.test

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ a.link:hover {
88

99
[
1010
["header-name", "Content-type:"],
11-
" text/css",
11+
" text/css\r\n",
12+
1213
["text-css", [
1314
["selector", "a.link:hover"],
1415
["punctuation", "{"],
16+
1517
["property", "color"],
1618
["punctuation", ":"],
1719
" red",
1820
["punctuation", ";"],
21+
1922
["punctuation", "}"]
2023
]]
2124
]

‎tests/languages/javascript+http/issue2733.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ transfer-encoding: chunked
4343
" timeout=60\r\n",
4444

4545
["header-name", "transfer-encoding:"],
46-
" chunked",
46+
" chunked\r\n",
47+
4748
["application-json", [
4849
["punctuation", "{"],
4950

‎tests/languages/javascript+http/javascript_inclusion.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ var a = true;
66

77
[
88
["header-name", "Content-type:"],
9-
" application/javascript",
9+
" application/javascript\r\n",
10+
1011
["application-javascript", [
1112
["keyword", "var"],
1213
" a ",

‎tests/languages/json+http/issue2733.test

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ transfer-encoding: chunked
4343
" timeout=60\r\n",
4444

4545
["header-name", "transfer-encoding:"],
46-
" chunked",
46+
" chunked\r\n",
47+
4748
["application-json", [
4849
["punctuation", "{"],
4950

@@ -109,4 +110,4 @@ transfer-encoding: chunked
109110

110111
["punctuation", "}"]
111112
]]
112-
]
113+
]
+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
HTTP/1.1 200 OK
2+
Access-Control-Allow-Credentials: true
3+
Access-Control-Allow-Origin: *
4+
Connection: keep-alive
5+
Content-Length: 523
6+
Content-Type: application/json
7+
Server: gunicorn/19.9.0
8+
X-Kong-Proxy-Latency: 1
9+
X-Kong-Upstream-Latency: 1
10+
{
11+
"args": {},
12+
"data": "",
13+
"files": {},
14+
"form": {},
15+
"headers": {
16+
"Accept": "*/*",
17+
"Accept-Encoding": "gzip, deflate",
18+
"Connection": "close",
19+
"Host": "httpbin.org",
20+
"User-Agent": "HTTPie/1.0.2",
21+
"X-Forwarded-Host": "example.com"
22+
},
23+
"json": null,
24+
"method": "GET",
25+
"origin": "172.19.0.1, 52.201.239.166",
26+
"url": "http://example.com/anything"
27+
}
28+
29+
----------------------------------------------------
30+
31+
[
32+
["response-status", [
33+
["http-version", "HTTP/1.1"],
34+
["status-code", "200"],
35+
["reason-phrase", "OK"]
36+
]],
37+
38+
["header-name", "Access-Control-Allow-Credentials:"],
39+
" true\r\n",
40+
41+
["header-name", "Access-Control-Allow-Origin:"],
42+
" *\r\n",
43+
44+
["header-name", "Connection:"],
45+
" keep-alive\r\n",
46+
47+
["header-name", "Content-Length:"],
48+
" 523\r\n",
49+
50+
["header-name", "Content-Type:"],
51+
" application/json\r\n",
52+
53+
["header-name", "Server:"],
54+
" gunicorn/19.9.0\r\n",
55+
56+
["header-name", "X-Kong-Proxy-Latency:"],
57+
" 1\r\n",
58+
59+
["header-name", "X-Kong-Upstream-Latency:"],
60+
" 1\r\n",
61+
62+
["application-json", [
63+
["punctuation", "{"],
64+
65+
["property", "\"args\""],
66+
["operator", ":"],
67+
["punctuation", "{"],
68+
["punctuation", "}"],
69+
["punctuation", ","],
70+
71+
["property", "\"data\""],
72+
["operator", ":"],
73+
["string", "\"\""],
74+
["punctuation", ","],
75+
76+
["property", "\"files\""],
77+
["operator", ":"],
78+
["punctuation", "{"],
79+
["punctuation", "}"],
80+
["punctuation", ","],
81+
82+
["property", "\"form\""],
83+
["operator", ":"],
84+
["punctuation", "{"],
85+
["punctuation", "}"],
86+
["punctuation", ","],
87+
88+
["property", "\"headers\""],
89+
["operator", ":"],
90+
["punctuation", "{"],
91+
92+
["property", "\"Accept\""],
93+
["operator", ":"],
94+
["string", "\"*/*\""],
95+
["punctuation", ","],
96+
97+
["property", "\"Accept-Encoding\""],
98+
["operator", ":"],
99+
["string", "\"gzip, deflate\""],
100+
["punctuation", ","],
101+
102+
["property", "\"Connection\""],
103+
["operator", ":"],
104+
["string", "\"close\""],
105+
["punctuation", ","],
106+
107+
["property", "\"Host\""],
108+
["operator", ":"],
109+
["string", "\"httpbin.org\""],
110+
["punctuation", ","],
111+
112+
["property", "\"User-Agent\""],
113+
["operator", ":"],
114+
["string", "\"HTTPie/1.0.2\""],
115+
["punctuation", ","],
116+
117+
["property", "\"X-Forwarded-Host\""],
118+
["operator", ":"],
119+
["string", "\"example.com\""],
120+
121+
["punctuation", "}"],
122+
["punctuation", ","],
123+
124+
["property", "\"json\""],
125+
["operator", ":"],
126+
["null", "null"],
127+
["punctuation", ","],
128+
129+
["property", "\"method\""],
130+
["operator", ":"],
131+
["string", "\"GET\""],
132+
["punctuation", ","],
133+
134+
["property", "\"origin\""],
135+
["operator", ":"],
136+
["string", "\"172.19.0.1, 52.201.239.166\""],
137+
["punctuation", ","],
138+
139+
["property", "\"url\""],
140+
["operator", ":"],
141+
["string", "\"http://example.com/anything\""],
142+
143+
["punctuation", "}"]
144+
]]
145+
]

‎tests/languages/json+http/json-suffix_inclusion.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Content-type: application/x.foo+bar+json
66

77
[
88
["header-name", "Content-type:"],
9-
" application/x.foo+bar+json",
9+
" application/x.foo+bar+json\r\n",
10+
1011
["application-json", [
1112
["punctuation", "{"],
1213
["property", "\"foo\""],

‎tests/languages/json+http/json_inclusion.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Content-type: application/json
66

77
[
88
["header-name", "Content-type:"],
9-
" application/json",
9+
" application/json\r\n",
10+
1011
["application-json", [
1112
["punctuation", "{"],
1213
["property", "\"foo\""],

‎tests/languages/markup+http/html_inclusion.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Content-type: text/html
66

77
[
88
["header-name", "Content-type:"],
9-
" text/html",
9+
" text/html\r\n",
10+
1011
["text-html", [
1112
["tag", [
1213
["tag", [

‎tests/languages/markup+http/issue2733.test

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ transfer-encoding: chunked
3232
" timeout=60\r\n",
3333

3434
["header-name", "transfer-encoding:"],
35-
" chunked",
35+
" chunked\r\n",
36+
3637
["application-xml", [
3738
["tag", [
3839
["tag", [
@@ -82,4 +83,4 @@ transfer-encoding: chunked
8283
["punctuation", ">"]
8384
]]
8485
]]
85-
]
86+
]

‎tests/languages/markup+http/text-xml_inclusion.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Content-type: text/xml
66

77
[
88
["header-name", "Content-type:"],
9-
" text/xml",
9+
" text/xml\r\n",
10+
1011
["text-xml", [
1112
["tag", [
1213
["tag", [

‎tests/languages/markup+http/xml-suffix_inclusion.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Content-type: text/x.anything+something-else+xml
66

77
[
88
["header-name", "Content-type:"],
9-
" text/x.anything+something-else+xml",
9+
" text/x.anything+something-else+xml\r\n",
10+
1011
["application-xml", [
1112
["tag", [
1213
["tag", [

‎tests/languages/markup+http/xml_inclusion.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Content-type: application/xml
66

77
[
88
["header-name", "Content-type:"],
9-
" application/xml",
9+
" application/xml\r\n",
10+
1011
["application-xml", [
1112
["tag", [
1213
["tag", [

0 commit comments

Comments
 (0)
Please sign in to comment.