Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions expfmt/text_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
dto "github.com/prometheus/client_model/go"

"github.com/golang/protobuf/proto"
"github.com/prometheus/common/log"
"github.com/prometheus/common/model"
)

Expand Down Expand Up @@ -125,6 +126,15 @@ func (p *TextParser) reset(in io.Reader) {
} else {
p.buf.Reset(in)
}

// Some clients like to throw in UTF-8 BOM chars
maybeBOM, err := p.buf.Peek(3)
if len(maybeBOM) == 3 && maybeBOM[0] == 0xEF && maybeBOM[1] == 0xBB && maybeBOM[2] == 0xBF && err == nil {
// The common case dealing with funny Windows clients
log.Debug("Discarding BOM")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use any logging anywhere in this package. It might come as a surprise to the (possibly very diverse) users, and it's pulling in another dependency. I think it's fine to silently swallow the BOMs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

On Tue, May 31, 2016 at 6:32 AM, Björn Rabenstein notifications@github.com
wrote:

In expfmt/text_parse.go
#42 (comment):

@@ -125,6 +126,15 @@ func (p *TextParser) reset(in io.Reader) {
} else {
p.buf.Reset(in)
}
+

  • // Some clients like to throw in UTF-8 BOM chars
  • maybeBOM, err := p.buf.Peek(3)
  • if len(maybeBOM) == 3 && maybeBOM[0] == 0xEF && maybeBOM[1] == 0xBB && maybeBOM[2] == 0xBF && err == nil {
  •   // The common case dealing with funny Windows clients
    
  •   log.Debug("Discarding BOM")
    

We don't use any logging anywhere in this package. It might come as a
surprise to the (possibly very diverse) users, and it's pulling in another
dependency. I think it's fine to silently swallow the BOMs.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/prometheus/common/pull/42/files/1e1e0c1c905808faedb252d7fbb96f35a43726f7#r65157940,
or mute the thread
https://github.com/notifications/unsubscribe/AStJnk1lrBxaqHlLQzUtcFti7h2pqeAYks5qHA5AgaJpZM4Iozt3
.

p.buf.Discard(3)
}

p.err = nil
p.lineCount = 0
if p.summaries == nil || len(p.summaries) > 0 {
Expand Down