Special whitespace characters, also good:)

Source: Internet
Author: User
Tags chr control characters html tags trim
Special space characters

In ASP programming, we often use the trim (RTrim, LTrim) function to remove some of the data at the beginning and end of the space, the author recently wrote an ASP chat room, has the following section of code:
<% Dim Name,title
Name=trim (Request.Form ("name"))
Password=trim (Request.Form ("password"))
If Name= "" or password= "' then Response.Redirect ' Error.asp?error=name&name=null '
Mydsn= "Dsn=test;uid=test;pwd=test"
Set Cn=server.createobject ("Adodb.connection")
Cn.open MyDSN
Sql= "INSERT into Test (Name,title) VALUES (' &name&" ', ' "&password&") "
Cn.execute (SQL)
Cn.close%>
The author used the Trim function to remove the beginning and end of the space, in general, this program executes very normal, but later I found someone unexpectedly can use a space to come in, meaning that the user's name is completely blank, But the author tried to use the space, but no matter can not pass (that is, the program monitored out), the beginning and end of the space are trimmed function to remove, even if there are spaces in the middle, the author needs to use a function of the middle of the space to remove, because the author uses the SQL database records under the user information, So I suspect he used something else so that the system can not see, so go to the record of the user data SQL database (I used this method to see the user with line breaks), but I still see the database to change the user's data is also a space, Does this mean that the user used a means to bypass my username and password monitoring??? I can't find a bug in the program. So can only ask the user, fortunately this user readily told the author, the original is "alt+255", hold down the ALT key and then press the keypad "2", "5", "5" will produce a more special things "space" Characters (the concept of the author is not quite clear, this is a control character, in some editors can see word2000, there should be other control characters), this space character is different from the traditional press SPACEBAR generated characters, its ASC code is 255, The traditional space type of the ASC code is the 32,trim function can only understand the ASC code 32 code and remove, so there appears a space user situation! In response to this situation, I designed the following two functions to remove this "space" character,
function Xuankong (str)
Dim result
Dim j
J=len (str)
Result= ""
Dim i
For i = 1 to J
Select Case Mid (str,i,1)
Case "<"
Result=result+ "<"
Case ">"
result=result+ ">"
Case Chr (34)
result=result+ "" "
Case "&"
result=result+ "&" The above code converts some HTML tags

Case Chr (255) ' Prevents special spaces
Result=result
Case Chr (13) ' prevents return characters
result=result+ "<br>"
Case Chr (10) ' prevent line breaks
result=result+ "<br>"
Case Else
Result=result+mid (str,i,1)
&



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.