-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gazette: Removes uses of structure keyword in templates (#1402)
This also adds `MarkupText` as a new column type TYPE: Bugfix LINK: OGC-1715
- Loading branch information
Showing
21 changed files
with
441 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from markupsafe import escape, Markup | ||
from sqlalchemy.types import TypeDecorator, TEXT | ||
|
||
|
||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from sqlalchemy.engine.interfaces import Dialect | ||
_Base = TypeDecorator[Markup] | ||
else: | ||
_Base = TypeDecorator | ||
|
||
|
||
class MarkupText(_Base): | ||
""" Text column that contains HTML/XML markup. """ | ||
|
||
impl = TEXT | ||
|
||
cache_ok = True | ||
|
||
def process_bind_param( | ||
self, | ||
value: str | None, | ||
dialect: 'Dialect' | ||
) -> Markup | None: | ||
|
||
return None if value is None else escape(value) | ||
|
||
def process_literal_param( | ||
self, | ||
value: str | None, | ||
dialect: 'Dialect' | ||
) -> Markup | None: | ||
|
||
return None if value is None else escape(value) | ||
|
||
def process_result_value( | ||
self, | ||
value: str | None, | ||
dialect: 'Dialect' | ||
) -> Markup | None: | ||
|
||
# NOTE: It would be safer to sanitize the text, in case someone | ||
# managed to bypass `process_bind_param` and inserted | ||
# unsanitized markup into the database. However, this would | ||
# also add a ton of static overhead. If we decide we want | ||
# the additional safety, we should use an approach like | ||
# OCQMS' lazy Sanitized text type. | ||
return None if value is None else Markup(value) # noqa: MS001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.