Skip to content

Commit

Permalink
bleach update (#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbesson authored Oct 12, 2022
1 parent bc1f709 commit 3664a51
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
23 changes: 15 additions & 8 deletions c2corg_api/markdown/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import markdown
import bleach
import bleach.css_sanitizer
import secrets
import logging
from threading import RLock
Expand Down Expand Up @@ -52,7 +53,7 @@ def _get_cleaner():
global _cleaner

if not _cleaner:
allowed_tags = bleach.ALLOWED_TAGS + [
allowed_tags = bleach.sanitizer.ALLOWED_TAGS + [
# headers
"h1", "h2", "h3", "h4", "h5", "h6",

Expand All @@ -71,7 +72,7 @@ def _get_cleaner():
"table", "tr", "td", "th", "tbody"
]

allowed_attributes = dict(bleach.ALLOWED_ATTRIBUTES)
allowed_attributes = dict(bleach.sanitizer.ALLOWED_ATTRIBUTES)
allowed_extra_attributes = {
"a": [
"c2c:role",
Expand Down Expand Up @@ -110,12 +111,18 @@ def _get_cleaner():

allowed_attributes[key] += allowed_extra_attributes[key]

_cleaner = bleach.Cleaner(tags=allowed_tags,
attributes=allowed_attributes,
styles=bleach.ALLOWED_STYLES + ["clear"],
protocols=bleach.ALLOWED_PROTOCOLS,
strip=False,
strip_comments=True)
css_sanitizer = bleach.css_sanitizer.CSSSanitizer(
allowed_css_properties=list(
bleach.css_sanitizer.ALLOWED_CSS_PROPERTIES)
+ ['clear'])

_cleaner = bleach.sanitizer.Cleaner(
tags=allowed_tags,
attributes=allowed_attributes,
css_sanitizer=css_sanitizer,
protocols=bleach.sanitizer.ALLOWED_PROTOCOLS,
strip=False,
strip_comments=True)

return _cleaner

Expand Down
2 changes: 1 addition & 1 deletion c2corg_api/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def wkb_to_shape(wkb_element):
""" Create a 2D Shapely shape from a WKB value. 3D and 4D geometries
are turned into 2D geometries.
"""
assert(isinstance(wkb_element, WKBElement))
assert (isinstance(wkb_element, WKBElement))
geometry = wkb.loads(bytes(wkb_element.data))
return shape(_force_2d(geometry))

Expand Down
2 changes: 1 addition & 1 deletion c2corg_api/tests/markdown/ptag/base.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div style="clear: both;"></div>
<div style="clear:both;"></div>
4 changes: 2 additions & 2 deletions c2corg_api/views/association.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _is_main_waypoint_association(association):


def _is_last_waypoint_of_route(association):
if not(association.parent_document_type == WAYPOINT_TYPE and
if not (association.parent_document_type == WAYPOINT_TYPE and
association.child_document_type == ROUTE_TYPE):
# other association type, nothing to check
return False
Expand All @@ -188,7 +188,7 @@ def _is_last_waypoint_of_route(association):


def _is_last_route_of_outing(association):
if not(association.parent_document_type == ROUTE_TYPE and
if not (association.parent_document_type == ROUTE_TYPE and
association.child_document_type == OUTING_TYPE):
# other association type, nothing to check
return False
Expand Down
3 changes: 2 additions & 1 deletion c2corg_api/views/document_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def __init__(self, request):

@restricted_json_view(validators=[validate_document_id])
def get(self):
""" Check if the authenticated user has tagged the given document as todo.
"""
Check if the authenticated user has tagged the given document as todo.
Request:
`GET` `tags/has/{document_id}`
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
alembic==1.8.1
apscheduler==3.9.1
bcrypt==4.0.1
bleach==4.1.0
bleach[css]==5.0.1
colander==1.8.3
dogpile.cache==1.1.8
elasticsearch==2.4.1
Expand Down

0 comments on commit 3664a51

Please sign in to comment.