diff --git a/go/cmd/dolt/commands/sql_statement_scanner.go b/go/cmd/dolt/commands/sql_statement_scanner.go index c21d239a785..61c3aee262f 100755 --- a/go/cmd/dolt/commands/sql_statement_scanner.go +++ b/go/cmd/dolt/commands/sql_statement_scanner.go @@ -96,16 +96,20 @@ func (s *streamScanner) Scan() bool { } // discard leading whitespace - for ; unicode.IsSpace(rune(s.buf[s.i])); s.i++ { - if s.buf[s.i] == '\n' { - s.lineNum++ - } + for { if s.i >= s.fill { if err := s.read(); err != nil { s.err = err return false } } + if !unicode.IsSpace(rune(s.buf[s.i])) { + break + } + if s.buf[s.i] == '\n' { + s.lineNum++ + } + s.i++ } s.truncate() diff --git a/go/cmd/dolt/commands/sql_statement_scanner_test.go b/go/cmd/dolt/commands/sql_statement_scanner_test.go index 7217e7b97b6..be47ddc7f75 100755 --- a/go/cmd/dolt/commands/sql_statement_scanner_test.go +++ b/go/cmd/dolt/commands/sql_statement_scanner_test.go @@ -187,6 +187,14 @@ insert into foo values (1,2,3)|`, }, lineNums: []int{1, 2}, }, + { + // https://github.com/dolthub/dolt/issues/8495 + input: strings.Repeat(" ", 4096) + `insert into foo values (1,2,3)`, + statements: []string{ + "insert into foo values (1,2,3)", + }, + lineNums: []int{1, 2}, + }, } for _, tt := range testcases {