Skip to content
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

Merged
merged 5 commits into from
Dec 12, 2023

Conversation

r1cardohj
Copy link
Contributor

hey grey, 根据代码厨房开源松的指示,我已经创建了人生中第一个pr哈哈哈,我认为把这个函数叫做cleanify感觉还不错,有点类似flask里面的jsonify,我也加入了一些单元测试,麻烦有空的时候review一下啦,如果有不足的地方请提出来,我可以修改并从中受益,感谢。

Copy link

codecov bot commented Dec 11, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (11ba463) 81.60% compared to head (8ef17b4) 81.20%.

❗ Current head 8ef17b4 differs from pull request most recent head 16779d8. Consider uploading reports for the commit 16779d8 to get more accurate results

Files Patch % Lines
flask_ckeditor/utils.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #75      +/-   ##
==========================================
- Coverage   81.60%   81.20%   -0.40%     
==========================================
  Files           3        3              
  Lines         125      133       +8     
==========================================
+ Hits          102      108       +6     
- Misses         23       25       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@greyli greyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulations on your first PR!

The overall changes are good, but there are a few small things that could be improved, see the comments for details.

CHANGES.rst Outdated
0.5.2
-----

Release date: 2023/12/09
Copy link
Member

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.

Suggested change
Release date: 2023/12/09
Release date: N/A

CHANGES.rst Outdated

Release date: 2023/12/09

- add ``cleanify`` function to ``flask_ckeditor.utils``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- add ``cleanify`` function to ``flask_ckeditor.utils``
- Add ``cleanify`` function to ``flask_ckeditor.utils`` for HTML sanity.

try:
import bleach
except ImportError:
warnings.warn('bleach is not installed,`cleanify` function will not be available')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
warnings.warn('bleach is not installed,`cleanify` function will not be available')
warnings.warn('The "bleach" library is not installed, `cleanify` function will not be available.')

"""clean the input from client, this function rely on bleach,


Args:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the docstring style that matches the existing code.

Comment on lines 34 to 39
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify the code to this:

Suggested change
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))
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=allow_tags or default_allowed_tags))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, i got it !

@r1cardohj
Copy link
Contributor Author

Thank you for your patient review !
i has fixed those questions .

@r1cardohj
Copy link
Contributor Author

i commit a new test case for bleach ImportError, i hope it can work.

@r1cardohj r1cardohj requested a review from greyli December 12, 2023 00:46
@r1cardohj r1cardohj changed the title add:create cleanify into utils moudel add:create cleanify into utils modules Dec 12, 2023
- Add docs
- Update dependencies
- Add extras_require config
- Remove the linkify call as it's kind of unexpected behavior of this function
@greyli greyli merged commit ec4364c into helloflask:master Dec 12, 2023
17 checks passed
@greyli
Copy link
Member

greyli commented Dec 12, 2023

Merged, thanks! I made some improvements at 16779d8

@r1cardohj r1cardohj deleted the bleach_dev branch December 12, 2023 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants