1
0
mirror of https://github.com/golang/go synced 2024-11-26 05:57:58 -07:00

- complete html-escaping also in printer.go

R=rsc
http://go/go-review/1017027
This commit is contained in:
Robert Griesemer 2009-11-04 10:59:25 -08:00
parent c8c3f1d5de
commit 6dbf7aa129

View File

@ -43,9 +43,12 @@ var (
htab = []byte{'\t'}; htab = []byte{'\t'};
htabs = [...]byte{'\t', '\t', '\t', '\t', '\t', '\t', '\t', '\t'}; htabs = [...]byte{'\t', '\t', '\t', '\t', '\t', '\t', '\t', '\t'};
newlines = [...]byte{'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'}; // more than maxNewlines newlines = [...]byte{'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'}; // more than maxNewlines
ampersand = strings.Bytes("&");
lessthan = strings.Bytes("<"); esc_quot = strings.Bytes("""); // shorter than """
greaterthan = strings.Bytes(">"); esc_apos = strings.Bytes("'"); // shorter than "'"
esc_amp = strings.Bytes("&");
esc_lt = strings.Bytes("<");
esc_gt = strings.Bytes(">");
) )
@ -145,7 +148,7 @@ func (p *printer) write(data []byte) {
// next segment start // next segment start
i0 = i+1; i0 = i+1;
case '&', '<', '>': case '"', '\'', '&', '<', '>':
if p.Mode & GenHTML != 0 { if p.Mode & GenHTML != 0 {
// write segment ending in b // write segment ending in b
p.write0(data[i0 : i]); p.write0(data[i0 : i]);
@ -153,9 +156,11 @@ func (p *printer) write(data []byte) {
// write HTML-escaped b // write HTML-escaped b
var esc []byte; var esc []byte;
switch b { switch b {
case '&': esc = ampersand; case '"': esc = esc_quot;
case '<': esc = lessthan; case '\'': esc = esc_apos;
case '>': esc = greaterthan; case '&': esc = esc_amp;
case '<': esc = esc_lt;
case '>': esc = esc_gt;
} }
p.write0(esc); p.write0(esc);