summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-11-04 10:59:25 -0800
committerRobert Griesemer <gri@golang.org>2009-11-04 10:59:25 -0800
commit6573a7a82a67f6259c544d4119ffa30b673560f1 (patch)
tree2401edfc806cbd6d370bc8b58fbfeb0bf0857946 /src
parent0a6114ba2cbb97c7fe98cb4ca2aa95227f81e3ac (diff)
downloadgolang-6573a7a82a67f6259c544d4119ffa30b673560f1.tar.gz
- complete html-escaping also in printer.go
R=rsc http://go/go-review/1017027
Diffstat (limited to 'src')
-rw-r--r--src/pkg/go/printer/printer.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/pkg/go/printer/printer.go b/src/pkg/go/printer/printer.go
index 265da0ebb..1511beee9 100644
--- a/src/pkg/go/printer/printer.go
+++ b/src/pkg/go/printer/printer.go
@@ -43,9 +43,12 @@ var (
htab = []byte{'\t'};
htabs = [...]byte{'\t', '\t', '\t', '\t', '\t', '\t', '\t', '\t'};
newlines = [...]byte{'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'}; // more than maxNewlines
- ampersand = strings.Bytes("&amp;");
- lessthan = strings.Bytes("&lt;");
- greaterthan = strings.Bytes("&gt;");
+
+ esc_quot = strings.Bytes("&#34;"); // shorter than "&quot;"
+ esc_apos = strings.Bytes("&#39;"); // shorter than "&apos;"
+ esc_amp = strings.Bytes("&amp;");
+ esc_lt = strings.Bytes("&lt;");
+ esc_gt = strings.Bytes("&gt;");
)
@@ -145,7 +148,7 @@ func (p *printer) write(data []byte) {
// next segment start
i0 = i+1;
- case '&', '<', '>':
+ case '"', '\'', '&', '<', '>':
if p.Mode & GenHTML != 0 {
// write segment ending in b
p.write0(data[i0 : i]);
@@ -153,9 +156,11 @@ func (p *printer) write(data []byte) {
// write HTML-escaped b
var esc []byte;
switch b {
- case '&': esc = ampersand;
- case '<': esc = lessthan;
- case '>': esc = greaterthan;
+ case '"': esc = esc_quot;
+ case '\'': esc = esc_apos;
+ case '&': esc = esc_amp;
+ case '<': esc = esc_lt;
+ case '>': esc = esc_gt;
}
p.write0(esc);