瀏覽代碼

[enhancement] auto-link URLs in Text Editor using bleach.linkify

version-14
Anand Doshi 9 年之前
父節點
當前提交
aaabd81329
共有 2 個文件被更改,包括 7 次插入5 次删除
  1. +1
    -2
      frappe/model/base_document.py
  2. +6
    -3
      frappe/utils/__init__.py

+ 1
- 2
frappe/model/base_document.py 查看文件

@@ -565,9 +565,8 @@ class BaseDocument(object):
or (self.docstatus==1 and not df.get("allow_on_submit"))):
continue


else:
sanitized_value = sanitize_html(value)
sanitized_value = sanitize_html(value, linkify=df.fieldtype=='Text Editor')

self.set(fieldname, sanitized_value)



+ 6
- 3
frappe/utils/__init__.py 查看文件

@@ -423,7 +423,7 @@ def watch(path, handler=None, debug=True):
observer.stop()
observer.join()

def sanitize_html(html):
def sanitize_html(html, linkify=False):
"""
Sanitize HTML tags, attributes and style to prevent XSS attacks
Based on bleach clean, bleach whitelist and HTML5lib's Sanitizer defaults
@@ -446,6 +446,9 @@ def sanitize_html(html):
styles=bleach_whitelist.all_styles,
strip_comments=False)

if linkify:
escaped_html = bleach.linkify(escaped_html)

return escaped_html

def is_json(text):
@@ -458,12 +461,12 @@ def is_json(text):
else:
return True

def markdown(text, sanitize=True):
def markdown(text, sanitize=True, linkify=True):
html = _markdown(text)

if sanitize:
html = html.replace("<!-- markdown -->", "")
html = sanitize_html(html)
html = sanitize_html(html, linkify=linkify)

return html



Loading…
取消
儲存