From 4e7b2a82d733fc705bc4a50192fb1bbe552bc687 Mon Sep 17 00:00:00 2001 From: Jxck Date: Sun, 17 Jan 2021 01:45:05 +0900 Subject: [PATCH] HTTP: Allow root path in request line (#2711) --- components/prism-http.js | 2 +- components/prism-http.min.js | 2 +- tests/languages/http/request-line_feature.test | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/components/prism-http.js b/components/prism-http.js index 4c20d4eff1..4f37679e35 100644 --- a/components/prism-http.js +++ b/components/prism-http.js @@ -1,7 +1,7 @@ (function (Prism) { Prism.languages.http = { 'request-line': { - pattern: /^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\s(?:https?:\/\/|\/)\S+\sHTTP\/[0-9.]+/m, + pattern: /^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\s(?:https?:\/\/|\/)\S*\sHTTP\/[0-9.]+/m, inside: { // HTTP Verb 'property': /^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b/, diff --git a/components/prism-http.min.js b/components/prism-http.min.js index 52a14a7c88..5b5b842f2c 100644 --- a/components/prism-http.min.js +++ b/components/prism-http.min.js @@ -1 +1 @@ -!function(t){t.languages.http={"request-line":{pattern:/^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\s(?:https?:\/\/|\/)\S+\sHTTP\/[0-9.]+/m,inside:{property:/^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b/,"attr-name":/:\w+/}},"response-status":{pattern:/^HTTP\/1.[01] \d.*/m,inside:{property:{pattern:/(^HTTP\/1.[01] )\d.*/i,lookbehind:!0}}},"header-name":{pattern:/^[\w-]+:(?=.)/m,alias:"keyword"}};var a,e,n,i=t.languages,p={"application/javascript":i.javascript,"application/json":i.json||i.javascript,"application/xml":i.xml,"text/xml":i.xml,"text/html":i.html,"text/css":i.css},r={"application/json":!0,"application/xml":!0};for(var s in p)if(p[s]){a=a||{};var T=r[s]?(void 0,n=(e=s).replace(/^[a-z]+\//,""),"(?:"+e+"|\\w+/(?:[\\w.-]+\\+)+"+n+"(?![+\\w.-]))"):s;a[s.replace(/\//g,"-")]={pattern:RegExp("(content-type:\\s*"+T+".*)(?:\\r?\\n|\\r){2}[\\s\\S]*","i"),lookbehind:!0,inside:p[s]}}a&&t.languages.insertBefore("http","header-name",a)}(Prism); \ No newline at end of file +!function(t){t.languages.http={"request-line":{pattern:/^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\s(?:https?:\/\/|\/)\S*\sHTTP\/[0-9.]+/m,inside:{property:/^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b/,"attr-name":/:\w+/}},"response-status":{pattern:/^HTTP\/1.[01] \d.*/m,inside:{property:{pattern:/(^HTTP\/1.[01] )\d.*/i,lookbehind:!0}}},"header-name":{pattern:/^[\w-]+:(?=.)/m,alias:"keyword"}};var a,e,n,i=t.languages,p={"application/javascript":i.javascript,"application/json":i.json||i.javascript,"application/xml":i.xml,"text/xml":i.xml,"text/html":i.html,"text/css":i.css},r={"application/json":!0,"application/xml":!0};for(var s in p)if(p[s]){a=a||{};var T=r[s]?(void 0,n=(e=s).replace(/^[a-z]+\//,""),"(?:"+e+"|\\w+/(?:[\\w.-]+\\+)+"+n+"(?![+\\w.-]))"):s;a[s.replace(/\//g,"-")]={pattern:RegExp("(content-type:\\s*"+T+".*)(?:\\r?\\n|\\r){2}[\\s\\S]*","i"),lookbehind:!0,inside:p[s]}}a&&t.languages.insertBefore("http","header-name",a)}(Prism); \ No newline at end of file diff --git a/tests/languages/http/request-line_feature.test b/tests/languages/http/request-line_feature.test index 70db1a9f38..b387625765 100644 --- a/tests/languages/http/request-line_feature.test +++ b/tests/languages/http/request-line_feature.test @@ -7,6 +7,7 @@ PATCH http://example.com HTTP/1.0 TRACE http://example.com HTTP/1.0 CONNECT http://example.com HTTP/1.0 GET /path/to/foo.html HTTP/1.1 +GET / HTTP/1.1 ---------------------------------------------------- @@ -48,9 +49,13 @@ GET /path/to/foo.html HTTP/1.1 ["request-line", [ ["property", "GET"], " /path/to/foo.html HTTP/1.1" + ]], + ["request-line", [ + ["property", "GET"], + " / HTTP/1.1" ]] ] ---------------------------------------------------- -Checks for request lines. \ No newline at end of file +Checks for request lines.