-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add:create cleanify
into utils
modules
#75
Changes from 2 commits
dac52d2
ab448fc
8ef17b4
4982834
16779d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,6 +6,13 @@ Changelog | |||||
|
||||||
Release date: - | ||||||
|
||||||
0.5.2 | ||||||
----- | ||||||
|
||||||
Release date: 2023/12/09 | ||||||
|
||||||
- add ``cleanify`` function to ``flask_ckeditor.utils`` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
|
||||||
0.5.1 | ||||||
----- | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,8 +1,13 @@ | ||||||||||||||||||||||
import os | ||||||||||||||||||||||
import uuid | ||||||||||||||||||||||
|
||||||||||||||||||||||
import warnings | ||||||||||||||||||||||
from flask import url_for | ||||||||||||||||||||||
|
||||||||||||||||||||||
try: | ||||||||||||||||||||||
import bleach | ||||||||||||||||||||||
except ImportError: | ||||||||||||||||||||||
warnings.warn('bleach is not installed,`cleanify` function will not be available') | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
def get_url(endpoint_or_url): | ||||||||||||||||||||||
if endpoint_or_url.startswith(('https://', 'http://', '/')): | ||||||||||||||||||||||
|
@@ -15,3 +20,20 @@ | |||||||||||||||||||||
ext = os.path.splitext(old_filename)[1] | ||||||||||||||||||||||
new_filename = uuid.uuid4().hex + ext | ||||||||||||||||||||||
return new_filename | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
def cleanify(text, *, allow_tags=None): | ||||||||||||||||||||||
"""clean the input from client, this function rely on bleach, | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
Args: | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the docstring style that matches the existing code. |
||||||||||||||||||||||
text (str): input | ||||||||||||||||||||||
allow_tags (Iterable[str], optional): if you don't want to use default `allow_tags` | ||||||||||||||||||||||
you can provide a Iterable which include html tag string like ['a', 'li',...] | ||||||||||||||||||||||
""" | ||||||||||||||||||||||
if allow_tags: | ||||||||||||||||||||||
return bleach.linkify(bleach.clean(text, tags=allow_tags)) | ||||||||||||||||||||||
default_allowed_tags = {'a', 'abbr', 'b', 'blockquote', 'code', | ||||||||||||||||||||||
'em', 'i', 'li', 'ol', 'pre', 'strong', 'ul', | ||||||||||||||||||||||
'h1', 'h2', 'h3', 'h4', 'h5', 'p'} | ||||||||||||||||||||||
return bleach.linkify(bleach.clean(text, tags=default_allowed_tags)) | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simplify the code to this:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool, i got it ! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,4 @@ wtforms==3.1.1 | |
# via | ||
# flask-admin | ||
# flask-wtf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ flask-wtf | |
flask-admin | ||
flask-sqlalchemy | ||
tablib | ||
bleach |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,3 +61,4 @@ wtforms==3.1.1 | |
# via | ||
# flask-admin | ||
# flask-wtf | ||
bleach==6.1.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ deps = | |
pytest | ||
coverage | ||
flask_wtf | ||
bleach | ||
|
||
[testenv:coverage] | ||
commands = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add a specific date here, I will update it when I make the new release.