简体   繁体   English

漂白剂回车

[英]Bleach carriage return

I am using python bleach library to sanitize the data entered by the user on a webpage. 我正在使用python漂白库清理用户在网页上输入的数据。 What I am doing is get user data, clean it using bleach clean and compare if cleaned data is different than original user data, if it is then throw a warning to the user to fix it.But I am facing an issue where If a user enters some data in a text area with a carriage return bleach.clean removes \\r in the original text and my comparison fails. 我正在做的是获取用户数据,使用bleach clean对其进行清理,并比较清理后的数据与原始用户数据是否不同,然后向用户发出警告以修复该数据。但是我面临一个问题,如果用户用回车符bleach在文本区域中输入一些数据。clean删除原始文本中的\\ r,我的比较失败。

For example: 例如:

If user enters abc (clicks enter) def 如果用户输入abc(单击输入)def

When we parse the html text box we get abc\\r\\ndef 当我们解析html文本框时,我们得到abc \\ r \\ ndef

and after bleach.clean() I am getting abc\\ndef 在bleach.clean()之后,我得到abc \\ ndef

I don't mind a carriage return in user input , but for some reason bleach is cleaning it, how do I prevent that? 我不介意在用户输入中输入回车符,但是由于某种原因,漂白剂正在清洁它,如何防止这种情况发生?

You can pre-sanitize the input before sending it to bleach by removing all carriage-returns . 您可以通过删除所有carriage-returns来对输入进行预消毒,然后再将其发送到bleach carriage-returns That should solve your problem. 那应该解决您的问题。 Here are some example use cases: 以下是一些示例用例:

string.translate Example: string.translate 示例:

from string import maketrans   # Required to call maketrans function.

intab = "aeiou"
outtab = "12345"
trantab = maketrans(intab, outtab)

str = "this is string example....wow!!!"
print str.translate(trantab)

string.translate Output: string.translate 输出:

th3s 3s str3ng 2x1mpl2....w4w!!!


string.replace Example: string.replace 示例:

str = "this is string example....wow!!! this is really string";
print str.replace("is", "was");

string.replace Output: string.replace 输出:

thwas was string example....wow!!! thwas was really string

Edit: You can also try overriding the tags kwarg while using bleach.clean 编辑:您还可以尝试在使用bleach.clean覆盖tags bleach.clean


Also you can check below for more information: 您也可以在下面查看更多信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM