mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-27 20:35:58 +03:00
Discard byte order mark (fix #962)
This commit is contained in:
parent
cf1b355d30
commit
1e1e69b90f
2 changed files with 17 additions and 0 deletions
|
@ -26,9 +26,20 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
// load prepares the lexer to scan an input for tokens.
|
// 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 {
|
func (l *lexer) load(input io.Reader) error {
|
||||||
l.reader = bufio.NewReader(input)
|
l.reader = bufio.NewReader(input)
|
||||||
l.line = 1
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,12 @@ func TestLexer(t *testing.T) {
|
||||||
{Line: 2, Text: "characters"},
|
{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 {
|
for i, testCase := range testCases {
|
||||||
|
|
Loading…
Reference in a new issue