Skip to content

Commit

Permalink
Discard byte order mark (fix caddyserver#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Jul 27, 2016
1 parent cf1b355 commit 1e1e69b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions caddyfile/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@ type (
)

// load prepares the lexer to scan an input for tokens.
// It discards any leading byte order mark.
func (l *lexer) load(input io.Reader) error {
l.reader = bufio.NewReader(input)
l.line = 1

// discard byte order mark, if present
firstCh, _, err := l.reader.ReadRune()
if err == nil && firstCh != 0xFEFF {
err := l.reader.UnreadRune()
if err != nil {
return err
}
}

return nil
}

Expand Down
6 changes: 6 additions & 0 deletions caddyfile/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ func TestLexer(t *testing.T) {
{Line: 2, Text: "characters"},
},
},
{
input: "\xEF\xBB\xBF:8080", // test with leading byte order mark
expected: []Token{
{Line: 1, Text: ":8080"},
},
},
}

for i, testCase := range testCases {
Expand Down

0 comments on commit 1e1e69b

Please sign in to comment.