Commit 1dfc8271b23218c89b7d8121ad80f2846f4e9daf

Michael Schmidt 2021-02-07T14:54:09

HTTP: Fixed body not being highlighted (#2734)

diff --git a/components/prism-http.js b/components/prism-http.js
index d8310a7..4dea0e4 100644
--- a/components/prism-http.js
+++ b/components/prism-http.js
@@ -90,7 +90,7 @@
 
 			var pattern = suffixTypes[contentType] ? getSuffixPattern(contentType) : contentType;
 			options[contentType.replace(/\//g, '-')] = {
-				pattern: RegExp('(content-type:\\s*' + pattern + '.*)(?:\\r?\\n|\\r){2}[\\s\\S]*', 'i'),
+				pattern: RegExp('(content-type:\\s*' + pattern + '(?:(?:\\r\\n?|\\n).+)*)(?:\\r?\\n|\\r){2}[\\s\\S]*', 'i'),
 				lookbehind: true,
 				inside: httpLanguages[contentType]
 			};
diff --git a/components/prism-http.min.js b/components/prism-http.min.js
index 955fbc5..4549361 100644
--- a/components/prism-http.min.js
+++ b/components/prism-http.min.js
@@ -1 +1 @@
-!function(t){t.languages.http={"request-line":{pattern:/^(?:GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI|SEARCH)\s(?:https?:\/\/|\/)\S*\sHTTP\/[0-9.]+/m,inside:{method:{pattern:/^[A-Z]+\b/,alias:"property"},"request-target":{pattern:/^(\s)(?:https?:\/\/|\/)\S*(?=\s)/,lookbehind:!0,alias:"url",inside:t.languages.uri},"http-version":{pattern:/^(\s)HTTP\/[0-9.]+/,lookbehind:!0,alias:"property"}}},"response-status":{pattern:/^HTTP\/[0-9.]+ \d+ .+/m,inside:{"http-version":{pattern:/^HTTP\/[0-9.]+/,alias:"property"},"status-code":{pattern:/^(\s)\d+(?=\s)/,lookbehind:!0,alias:"number"},"reason-phrase":{pattern:/^(\s).+/,lookbehind:!0,alias:"string"}}},"header-name":{pattern:/^[\w-]+:(?=.)/m,alias:"keyword"}};var a,e,s,n=t.languages,i={"application/javascript":n.javascript,"application/json":n.json||n.javascript,"application/xml":n.xml,"text/xml":n.xml,"text/html":n.html,"text/css":n.css},r={"application/json":!0,"application/xml":!0};for(var p in i)if(i[p]){a=a||{};var o=r[p]?(void 0,s=(e=p).replace(/^[a-z]+\//,""),"(?:"+e+"|\\w+/(?:[\\w.-]+\\+)+"+s+"(?![+\\w.-]))"):p;a[p.replace(/\//g,"-")]={pattern:RegExp("(content-type:\\s*"+o+".*)(?:\\r?\\n|\\r){2}[\\s\\S]*","i"),lookbehind:!0,inside:i[p]}}a&&t.languages.insertBefore("http","header-name",a)}(Prism);
\ No newline at end of file
+!function(t){t.languages.http={"request-line":{pattern:/^(?:GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI|SEARCH)\s(?:https?:\/\/|\/)\S*\sHTTP\/[0-9.]+/m,inside:{method:{pattern:/^[A-Z]+\b/,alias:"property"},"request-target":{pattern:/^(\s)(?:https?:\/\/|\/)\S*(?=\s)/,lookbehind:!0,alias:"url",inside:t.languages.uri},"http-version":{pattern:/^(\s)HTTP\/[0-9.]+/,lookbehind:!0,alias:"property"}}},"response-status":{pattern:/^HTTP\/[0-9.]+ \d+ .+/m,inside:{"http-version":{pattern:/^HTTP\/[0-9.]+/,alias:"property"},"status-code":{pattern:/^(\s)\d+(?=\s)/,lookbehind:!0,alias:"number"},"reason-phrase":{pattern:/^(\s).+/,lookbehind:!0,alias:"string"}}},"header-name":{pattern:/^[\w-]+:(?=.)/m,alias:"keyword"}};var a,e,s,n=t.languages,r={"application/javascript":n.javascript,"application/json":n.json||n.javascript,"application/xml":n.xml,"text/xml":n.xml,"text/html":n.html,"text/css":n.css},i={"application/json":!0,"application/xml":!0};for(var p in r)if(r[p]){a=a||{};var o=i[p]?(void 0,s=(e=p).replace(/^[a-z]+\//,""),"(?:"+e+"|\\w+/(?:[\\w.-]+\\+)+"+s+"(?![+\\w.-]))"):p;a[p.replace(/\//g,"-")]={pattern:RegExp("(content-type:\\s*"+o+"(?:(?:\\r\\n?|\\n).+)*)(?:\\r?\\n|\\r){2}[\\s\\S]*","i"),lookbehind:!0,inside:r[p]}}a&&t.languages.insertBefore("http","header-name",a)}(Prism);
\ No newline at end of file
diff --git a/tests/languages/javascript+http/issue2733.test b/tests/languages/javascript+http/issue2733.test
new file mode 100644
index 0000000..cdd0e2e
--- /dev/null
+++ b/tests/languages/javascript+http/issue2733.test
@@ -0,0 +1,112 @@
+HTTP/1.1 200 OK
+connection: keep-alive
+content-type: application/json
+date: Sat, 23 Jan 2021 20:36:14 GMT
+keep-alive: timeout=60
+transfer-encoding: chunked
+
+{
+    "id": 1,
+    "name": "John Doe",
+    "userName": "jdoe",
+    "email": "whatever@something.zzz",
+    "phone": "1234567890",
+    "birthDate": "1878-05-06",
+    "address": {
+       "street": "Fake St",
+        "street2": "Apt. 556",
+        "city": "Gwenborough",
+        "state": "ZZ",
+        "zip": "12345"
+    }
+}
+
+----------------------------------------------------
+
+[
+	["response-status", [
+		["http-version", "HTTP/1.1"],
+		["status-code", "200"],
+		["reason-phrase", "OK"]
+	]],
+
+	["header-name", "connection:"],
+	" keep-alive\r\n",
+
+	["header-name", "content-type:"],
+	" application/json\r\n",
+
+	["header-name", "date:"],
+	" Sat, 23 Jan 2021 20:36:14 GMT\r\n",
+
+	["header-name", "keep-alive:"],
+	" timeout=60\r\n",
+
+	["header-name", "transfer-encoding:"],
+	" chunked",
+	["application-json", [
+		["punctuation", "{"],
+
+		["string", "\"id\""],
+		["operator", ":"],
+		["number", "1"],
+		["punctuation", ","],
+
+		["string", "\"name\""],
+		["operator", ":"],
+		["string", "\"John Doe\""],
+		["punctuation", ","],
+
+		["string", "\"userName\""],
+		["operator", ":"],
+		["string", "\"jdoe\""],
+		["punctuation", ","],
+
+		["string", "\"email\""],
+		["operator", ":"],
+		["string", "\"whatever@something.zzz\""],
+		["punctuation", ","],
+
+		["string", "\"phone\""],
+		["operator", ":"],
+		["string", "\"1234567890\""],
+		["punctuation", ","],
+
+		["string", "\"birthDate\""],
+		["operator", ":"],
+		["string", "\"1878-05-06\""],
+		["punctuation", ","],
+
+		["string", "\"address\""],
+		["operator", ":"],
+		["punctuation", "{"],
+
+		["string", "\"street\""],
+		["operator", ":"],
+		["string", "\"Fake St\""],
+		["punctuation", ","],
+
+		["string", "\"street2\""],
+		["operator", ":"],
+		["string", "\"Apt. 556\""],
+		["punctuation", ","],
+
+		["string", "\"city\""],
+		["operator", ":"],
+		["string", "\"Gwenborough\""],
+		["punctuation", ","],
+
+		["string", "\"state\""],
+		["operator", ":"],
+		["string", "\"ZZ\""],
+		["punctuation", ","],
+
+		["string", "\"zip\""],
+		["operator", ":"],
+		["string", "\"12345\""],
+
+		["punctuation", "}"],
+
+		["punctuation", "}"]
+	]]
+]
\ No newline at end of file
diff --git a/tests/languages/json+http/issue2733.test b/tests/languages/json+http/issue2733.test
new file mode 100644
index 0000000..024da6b
--- /dev/null
+++ b/tests/languages/json+http/issue2733.test
@@ -0,0 +1,112 @@
+HTTP/1.1 200 OK
+connection: keep-alive
+content-type: application/json
+date: Sat, 23 Jan 2021 20:36:14 GMT
+keep-alive: timeout=60
+transfer-encoding: chunked
+
+{
+    "id": 1,
+    "name": "John Doe",
+    "userName": "jdoe",
+    "email": "whatever@something.zzz",
+    "phone": "1234567890",
+    "birthDate": "1878-05-06",
+    "address": {
+       "street": "Fake St",
+        "street2": "Apt. 556",
+        "city": "Gwenborough",
+        "state": "ZZ",
+        "zip": "12345"
+    }
+}
+
+----------------------------------------------------
+
+[
+	["response-status", [
+		["http-version", "HTTP/1.1"],
+		["status-code", "200"],
+		["reason-phrase", "OK"]
+	]],
+
+	["header-name", "connection:"],
+	" keep-alive\r\n",
+
+	["header-name", "content-type:"],
+	" application/json\r\n",
+
+	["header-name", "date:"],
+	" Sat, 23 Jan 2021 20:36:14 GMT\r\n",
+
+	["header-name", "keep-alive:"],
+	" timeout=60\r\n",
+
+	["header-name", "transfer-encoding:"],
+	" chunked",
+	["application-json", [
+		["punctuation", "{"],
+
+		["property", "\"id\""],
+		["operator", ":"],
+		["number", "1"],
+		["punctuation", ","],
+
+		["property", "\"name\""],
+		["operator", ":"],
+		["string", "\"John Doe\""],
+		["punctuation", ","],
+
+		["property", "\"userName\""],
+		["operator", ":"],
+		["string", "\"jdoe\""],
+		["punctuation", ","],
+
+		["property", "\"email\""],
+		["operator", ":"],
+		["string", "\"whatever@something.zzz\""],
+		["punctuation", ","],
+
+		["property", "\"phone\""],
+		["operator", ":"],
+		["string", "\"1234567890\""],
+		["punctuation", ","],
+
+		["property", "\"birthDate\""],
+		["operator", ":"],
+		["string", "\"1878-05-06\""],
+		["punctuation", ","],
+
+		["property", "\"address\""],
+		["operator", ":"],
+		["punctuation", "{"],
+
+		["property", "\"street\""],
+		["operator", ":"],
+		["string", "\"Fake St\""],
+		["punctuation", ","],
+
+		["property", "\"street2\""],
+		["operator", ":"],
+		["string", "\"Apt. 556\""],
+		["punctuation", ","],
+
+		["property", "\"city\""],
+		["operator", ":"],
+		["string", "\"Gwenborough\""],
+		["punctuation", ","],
+
+		["property", "\"state\""],
+		["operator", ":"],
+		["string", "\"ZZ\""],
+		["punctuation", ","],
+
+		["property", "\"zip\""],
+		["operator", ":"],
+		["string", "\"12345\""],
+
+		["punctuation", "}"],
+
+		["punctuation", "}"]
+	]]
+]
\ No newline at end of file
diff --git a/tests/languages/markup+http/issue2733.test b/tests/languages/markup+http/issue2733.test
new file mode 100644
index 0000000..01b7c2b
--- /dev/null
+++ b/tests/languages/markup+http/issue2733.test
@@ -0,0 +1,85 @@
+HTTP/1.1 200 OK
+connection: keep-alive
+content-type: application/xml
+date: Sat, 23 Jan 2021 20:36:14 GMT
+keep-alive: timeout=60
+transfer-encoding: chunked
+
+<xml>
+    <one>Data</one>
+    <two>More Data</two>
+</xml>
+
+----------------------------------------------------
+
+[
+	["response-status", [
+		["http-version", "HTTP/1.1"],
+		["status-code", "200"],
+		["reason-phrase", "OK"]
+	]],
+
+	["header-name", "connection:"],
+	" keep-alive\r\n",
+
+	["header-name", "content-type:"],
+	" application/xml\r\n",
+
+	["header-name", "date:"],
+	" Sat, 23 Jan 2021 20:36:14 GMT\r\n",
+
+	["header-name", "keep-alive:"],
+	" timeout=60\r\n",
+
+	["header-name", "transfer-encoding:"],
+	" chunked",
+	["application-xml", [
+		["tag", [
+			["tag", [
+				["punctuation", "<"],
+				"xml"
+			]],
+			["punctuation", ">"]
+		]],
+
+		["tag", [
+			["tag", [
+				["punctuation", "<"],
+				"one"
+			]],
+			["punctuation", ">"]
+		]],
+		"Data",
+		["tag", [
+			["tag", [
+				["punctuation", "</"],
+				"one"
+			]],
+			["punctuation", ">"]
+		]],
+
+		["tag", [
+			["tag", [
+				["punctuation", "<"],
+				"two"
+			]],
+			["punctuation", ">"]
+		]],
+		"More Data",
+		["tag", [
+			["tag", [
+				["punctuation", "</"],
+				"two"
+			]],
+			["punctuation", ">"]
+		]],
+
+		["tag", [
+			["tag", [
+				["punctuation", "</"],
+				"xml"
+			]],
+			["punctuation", ">"]
+		]]
+	]]
+]
\ No newline at end of file