Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
telegraf-nftables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Due to inactivity, this project is scheduled to be deleted on 2035-04-24.
Why is this scheduled?
Show more breadcrumbs
vqgroup
telegraf-nftables
Commits
86144452
Commit
86144452
authored
7 years ago
by
Daniel Nelson
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix parsing of JSON with a UTF8 BOM in httpjson (#3267)
parent
f23d1eb0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/inputs/httpjson/httpjson.go
+6
-1
6 additions, 1 deletion
plugins/inputs/httpjson/httpjson.go
plugins/inputs/httpjson/httpjson_test.go
+15
-0
15 additions, 0 deletions
plugins/inputs/httpjson/httpjson_test.go
with
21 additions
and
1 deletion
plugins/inputs/httpjson/httpjson.go
+
6
−
1
View file @
86144452
package
httpjson
package
httpjson
import
(
import
(
"bytes"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
...
@@ -15,6 +16,10 @@ import (
...
@@ -15,6 +16,10 @@ import (
"github.com/influxdata/telegraf/plugins/parsers"
"github.com/influxdata/telegraf/plugins/parsers"
)
)
var
(
utf8BOM
=
[]
byte
(
"
\xef\xbb\xbf
"
)
)
// HttpJson struct
// HttpJson struct
type
HttpJson
struct
{
type
HttpJson
struct
{
Name
string
Name
string
...
@@ -170,7 +175,6 @@ func (h *HttpJson) gatherServer(
...
@@ -170,7 +175,6 @@ func (h *HttpJson) gatherServer(
serverURL
string
,
serverURL
string
,
)
error
{
)
error
{
resp
,
responseTime
,
err
:=
h
.
sendRequest
(
serverURL
)
resp
,
responseTime
,
err
:=
h
.
sendRequest
(
serverURL
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -266,6 +270,7 @@ func (h *HttpJson) sendRequest(serverURL string) (string, float64, error) {
...
@@ -266,6 +270,7 @@ func (h *HttpJson) sendRequest(serverURL string) (string, float64, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
string
(
body
),
responseTime
,
err
return
string
(
body
),
responseTime
,
err
}
}
body
=
bytes
.
TrimPrefix
(
body
,
utf8BOM
)
// Process response
// Process response
if
resp
.
StatusCode
!=
http
.
StatusOK
{
if
resp
.
StatusCode
!=
http
.
StatusOK
{
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/httpjson/httpjson_test.go
+
15
−
0
View file @
86144452
...
@@ -560,3 +560,18 @@ func TestHttpJsonArray200Tags(t *testing.T) {
...
@@ -560,3 +560,18 @@ func TestHttpJsonArray200Tags(t *testing.T) {
}
}
}
}
}
}
var
jsonBOM
=
[]
byte
(
"
\xef\xbb\xbf
[{
\"
value
\"
:17}]"
)
// TestHttpJsonBOM tests that UTF-8 JSON with a BOM can be parsed
func
TestHttpJsonBOM
(
t
*
testing
.
T
)
{
httpjson
:=
genMockHttpJson
(
string
(
jsonBOM
),
200
)
for
_
,
service
:=
range
httpjson
{
if
service
.
Name
==
"other_webapp"
{
var
acc
testutil
.
Accumulator
err
:=
acc
.
GatherError
(
service
.
Gather
)
require
.
NoError
(
t
,
err
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment