msgviewer: set max line length to 1 GB
some people send around huge html without any newline in between. This did overflow the default 64KB buffer of bufio.Scanner. If something can't fit in a GB there's no hope left Also, ignoring errors is bad mkey
This commit is contained in:
parent
01885e2448
commit
1bab1754f0
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -641,11 +642,18 @@ func (pv *PartViewer) copyFilterOutToPager() {
|
||||||
|
|
||||||
func (pv *PartViewer) copySourceToSinkStripAnsi() {
|
func (pv *PartViewer) copySourceToSinkStripAnsi() {
|
||||||
scanner := bufio.NewScanner(pv.source)
|
scanner := bufio.NewScanner(pv.source)
|
||||||
|
// some people send around huge html without any newline in between
|
||||||
|
// this did overflow the default 64KB buffer of bufio.Scanner.
|
||||||
|
// If something can't fit in a GB there's no hope left
|
||||||
|
scanner.Buffer(nil, 1024*1024*1024)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
text := scanner.Text()
|
text := scanner.Text()
|
||||||
text = ansi.ReplaceAllString(text, "")
|
text = ansi.ReplaceAllString(text, "")
|
||||||
io.WriteString(pv.sink, text+"\n")
|
io.WriteString(pv.sink, text+"\n")
|
||||||
}
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "failed to read line: %v\n", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pv *PartViewer) Invalidate() {
|
func (pv *PartViewer) Invalidate() {
|
||||||
|
|
Loading…
Reference in New Issue