In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the design method of character escape in web framework". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The escape of special characters (escaping) is very important for web security and user experience. Because different characters need to be escaped differently in different locations of HTML, various framework / scripting languages provide several different functions. However, what we want to introduce here is Go's own Web framework, which can recognize HTML and automatically choose the escape ambiguity to carry on the correct escape.
Go language is an open source project initiated by Google, and now there are a large number of outsiders involved in the development, including Chinese programmers. Because it is an emerging language, there are many experiences and lessons in designing previous programming languages. In order to meet the needs of current development, Go comes with the Web framework: template.
One of the features of template is that it parses the HTML syntax in the template to know the position of the variable to be replaced in the web page, so as to escape correctly. Here is an example program (template needs to use "html/template" when the edges and corners are omitted):
T, _: = template.New ("foo") .Parse
`{{.}` +
`var s ='# Hello? I\ x27m David=' `)
T.ExecuteTemplate (os.Stdout, "foo", "# Hello? iTunm David=")
There are only two sentences:
Compile a template that contains the HTML framework with some variables. Here are four {{.}}
Execute the template, giving the value of the variable, where the values of the four variables are all "# Hello? identity David=", an odd string that contains and many characters that need to be escaped. The result of the conversion is output directly to the standard output.
Here is the output:
# Hello? I believe 39 Hello m David=var s ='# Hello? I\ x27m David='
I marked the results of the conversion of the four variables in red bold. You can find that although the same value is given when the call is made, it is different after the conversion. The following table is listed for comparison:
Position value
HTML body # Hello? I believe 39 m David=
Attribute has a value of # Hello? I believe 39 m David=
URL Path # Hello?%20I%27m%20David=
The value of URL Query is 23Hello%3f%20I%27m%20David%3d.
Javascript string # Hello? I\ x27m David=
This is the end of the content of "what is the design method of character escape in web framework". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.