Skip to content

Commit

Permalink
HTTP: Fixed body not being highlighted (#2734)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Feb 7, 2021
1 parent ccc73ab commit 1dfc827
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/prism-http.js
Expand Up @@ -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]
};
Expand Down
2 changes: 1 addition & 1 deletion components/prism-http.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 112 additions & 0 deletions 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", "}"]
]]
]
112 changes: 112 additions & 0 deletions 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", "}"]
]]
]
85 changes: 85 additions & 0 deletions 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", ">"]
]]
]]
]

0 comments on commit 1dfc827

Please sign in to comment.