mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-25 21:39:02 +02:00
Properly syntax highlight HTTP body
Currently given an example like: ```http GET /foo HTTP/1.1 Content-Type: application/json User-Agent: foo {"hello": "world"} ``` It will fail to highlight because the content type will get reset when processing the `User-Agent` header. The is particularly problematic because Go maps are randomly ordered and `http.Request` use a map for headers, meaning on some runs you could get highlighting and on others it would silently fail if you are generating the above from an `http.Request`. This PR fixes it by resetting `isContentType` once we've read the actual content type, which prevents replacing it with later literals.
This commit is contained in:
parent
e9d4ea1fe5
commit
eafa8e1c69
@ -85,6 +85,7 @@ func (d *httpBodyContentTyper) Tokenise(options *TokeniseOptions, text string) (
|
||||
}
|
||||
case token.Type == Literal && isContentType:
|
||||
{
|
||||
isContentType = false
|
||||
contentType = strings.TrimSpace(token.Value)
|
||||
pos := strings.Index(contentType, ";")
|
||||
if pos > 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user