Commit ad6c97ec authored by Openset's avatar Openset

Update: Htmlquote Htmlunquote

parent d3d97de3
...@@ -17,6 +17,7 @@ package beego ...@@ -17,6 +17,7 @@ package beego
import ( import (
"errors" "errors"
"fmt" "fmt"
"html"
"html/template" "html/template"
"net/url" "net/url"
"reflect" "reflect"
...@@ -207,14 +208,12 @@ func Htmlquote(text string) string { ...@@ -207,14 +208,12 @@ func Htmlquote(text string) string {
'<'&">' '<'&">'
*/ */
text = strings.Replace(text, "&", "&", -1) // Must be done first! text = html.EscapeString(text)
text = strings.Replace(text, "<", "&lt;", -1) text = strings.NewReplacer(
text = strings.Replace(text, ">", "&gt;", -1) `“`, "&ldquo;",
text = strings.Replace(text, "'", "&#39;", -1) `”`, "&rdquo;",
text = strings.Replace(text, "\"", "&quot;", -1) ` `, "&nbsp;",
text = strings.Replace(text, "“", "&ldquo;", -1) ).Replace(text)
text = strings.Replace(text, "”", "&rdquo;", -1)
text = strings.Replace(text, " ", "&nbsp;", -1)
return strings.TrimSpace(text) return strings.TrimSpace(text)
} }
...@@ -228,17 +227,7 @@ func Htmlunquote(text string) string { ...@@ -228,17 +227,7 @@ func Htmlunquote(text string) string {
'<\\'&">' '<\\'&">'
*/ */
// strings.Replace(s, old, new, n) text = html.UnescapeString(text)
// 在s字符串中,把old字符串替换为new字符串,n表示替换的次数,小于0表示全部替换
text = strings.Replace(text, "&nbsp;", " ", -1)
text = strings.Replace(text, "&rdquo;", "”", -1)
text = strings.Replace(text, "&ldquo;", "“", -1)
text = strings.Replace(text, "&quot;", "\"", -1)
text = strings.Replace(text, "&#39;", "'", -1)
text = strings.Replace(text, "&gt;", ">", -1)
text = strings.Replace(text, "&lt;", "<", -1)
text = strings.Replace(text, "&amp;", "&", -1) // Must be done last!
return strings.TrimSpace(text) return strings.TrimSpace(text)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment