Procházet zdrojové kódy

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

version-14
Anand Doshi před 9 roky
rodič
revize
aaabd81329
2 změnil soubory, kde provedl 7 přidání a 5 odebrání
  1. +1
    -2
      frappe/model/base_document.py
  2. +6
    -3
      frappe/utils/__init__.py

+ 1
- 2
frappe/model/base_document.py Zobrazit soubor

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



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


self.set(fieldname, sanitized_value) self.set(fieldname, sanitized_value)




+ 6
- 3
frappe/utils/__init__.py Zobrazit soubor

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


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


if linkify:
escaped_html = bleach.linkify(escaped_html)

return escaped_html return escaped_html


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


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


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


return html return html




Načítá se…
Zrušit
Uložit