摘要: 需求:这里以转义特殊字符串为例 import re # 替换字符串的映射 map_str = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;", } def callback(match): """ 返回替 阅读全文
posted @ 2020-11-30 15:20 小粉优化大师 阅读(256) 评论(0) 推荐(0) 编辑
摘要: 需求:在做Web开发过程中,经常遇到特殊符号需要转义为浏览器认为是字符串的数据,减少前端的攻击。 注意:此代码来源Tornado源码 #!/usr/bin/env python # -*- coding: utf-8 -*- import re import html.entities import 阅读全文
posted @ 2020-11-30 15:17 小粉优化大师 阅读(558) 评论(0) 推荐(0) 编辑