Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
467c726e
Commit
467c726e
authored
Nov 04, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add " and ' to list of html-escaped chars
R=rsc
http://go/go-review/1017025
parent
796e29eb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
10 deletions
+19
-10
format.go
src/pkg/template/format.go
+19
-10
No files found.
src/pkg/template/format.go
View file @
467c726e
...
...
@@ -21,29 +21,38 @@ func StringFormatter(w io.Writer, value interface{}, format string) {
fmt
.
Fprint
(
w
,
value
);
}
var
esc_amp
=
strings
.
Bytes
(
"&"
)
var
esc_lt
=
strings
.
Bytes
(
"<"
)
var
esc_gt
=
strings
.
Bytes
(
">"
)
var
(
esc_quot
=
strings
.
Bytes
(
"""
);
// shorter than """
esc_apos
=
strings
.
Bytes
(
"'"
);
// shorter than "'"
esc_amp
=
strings
.
Bytes
(
"&"
);
esc_lt
=
strings
.
Bytes
(
"<"
);
esc_gt
=
strings
.
Bytes
(
">"
);
)
// HtmlEscape writes to w the properly escaped HTML equivalent
// of the plain text data s.
func
HtmlEscape
(
w
io
.
Writer
,
s
[]
byte
)
{
var
esc
[]
byte
;
last
:=
0
;
for
i
,
c
:=
range
s
{
if
c
==
'&'
||
c
==
'<'
||
c
==
'>'
{
w
.
Write
(
s
[
last
:
i
]);
switch
c
{
case
'"'
:
esc
=
esc_quot
;
case
'\'
'
:
esc
=
esc_apos
;
case
'&'
:
w
.
Write
(
esc_amp
)
;
esc
=
esc_amp
;
case
'<'
:
w
.
Write
(
esc_lt
)
;
esc
=
esc_lt
;
case
'>'
:
w
.
Write
(
esc_gt
);
esc
=
esc_gt
;
default
:
continue
;
}
w
.
Write
(
s
[
last
:
i
]);
w
.
Write
(
esc
);
last
=
i
+
1
;
}
}
w
.
Write
(
s
[
last
:
len
(
s
)]);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment