-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sanitizing): Return ampersand after sanitizing in validator and p…
…atch for de-sanitize & to &
- Loading branch information
1 parent
59384ef
commit 77b0d32
Showing
3 changed files
with
124 additions
and
0 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
116 changes: 116 additions & 0 deletions
116
src/apps/shared/commands/patches/m2_6757_replace_amp_sanitizer.py
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,116 @@ | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
UPDATE_APPLET_SQL = """ | ||
UPDATE applets | ||
SET | ||
"display_name" = regexp_replace("display_name", '&', '&', 'g'), | ||
"about" = regexp_replace(about::text, '&', '&', 'g')::jsonb, | ||
"description" = regexp_replace(description::text, '&', '&', 'g')::jsonb | ||
WHERE | ||
"display_name" LIKE '%&%' | ||
OR (about->>'en' LIKE '%&%' OR about->>'fr' LIKE '%&%') | ||
OR (description->>'en' LIKE '%&%' OR description->>'fr' LIKE '%&%'); | ||
""" | ||
|
||
UPDATE_APPLET_HISTORY_SQL = """ | ||
UPDATE applet_histories | ||
SET | ||
"display_name" = regexp_replace("display_name", '&', '&', 'g'), | ||
"about" = regexp_replace(about::text, '&', '&', 'g')::jsonb, | ||
"description" = regexp_replace(description::text, '&', '&', 'g')::jsonb | ||
WHERE | ||
"display_name" LIKE '%&%' | ||
OR (about->>'en' LIKE '%&%' OR about->>'fr' LIKE '%&%') | ||
OR (description->>'en' LIKE '%&%' OR description->>'fr' LIKE '%&%'); | ||
""" | ||
|
||
UPDATE_ACTIVITY_SQL = """ | ||
UPDATE activities | ||
SET | ||
"name" = regexp_replace("name", '&', '&', 'g'), | ||
"description" = regexp_replace(description::text, '&', '&', 'g')::jsonb | ||
WHERE "name" LIKE '%&%' OR (description->>'en' LIKE '%&%' OR description->>'fr' LIKE '%&%'); | ||
""" | ||
|
||
UPDATE_ACTIVITY_HISTORY_SQL = """ | ||
UPDATE activity_histories | ||
SET | ||
"name" = regexp_replace("name", '&', '&', 'g'), | ||
"description" = regexp_replace(description::text, '&', '&', 'g')::jsonb | ||
WHERE "name" LIKE '%&%' OR (description->>'en' LIKE '%&%' OR description->>'fr' LIKE '%&%'); | ||
""" | ||
|
||
|
||
UPDATE_ACTIVITY_SCORES_AND_REPORTS_SQL = """ | ||
UPDATE activities | ||
SET scores_and_reports = regexp_replace(scores_and_reports::text, '&', '&', 'g')::jsonb | ||
WHERE EXISTS ( | ||
SELECT 1 | ||
FROM jsonb_array_elements(scores_and_reports->'reports') AS report | ||
WHERE report->>'message' LIKE '%&%' | ||
); | ||
""" | ||
|
||
UPDATE_ACTIVITY_HISTORY_SCORES_AND_REPORTS_SQL = """ | ||
UPDATE activity_histories | ||
SET scores_and_reports = regexp_replace(scores_and_reports::text, '&', '&', 'g')::jsonb | ||
WHERE EXISTS ( | ||
SELECT 1 | ||
FROM jsonb_array_elements(scores_and_reports->'reports') AS report | ||
WHERE report->>'message' LIKE '%&%' | ||
); | ||
""" | ||
|
||
UPDATE_ACTIVITY_ITEM_SQL = """ | ||
UPDATE activity_items | ||
SET | ||
"name" = regexp_replace("name", '&', '&', 'g'), | ||
"question" = regexp_replace(question::text, '&', '&', 'g')::jsonb | ||
WHERE "name" LIKE '%&%' OR (question->>'en' LIKE '%&%' OR question->>'fr' LIKE '%&%'); | ||
""" | ||
UPDATE_ACTIVITY_ITEM_HISTORY_SQL = """ | ||
UPDATE activity_item_histories | ||
SET | ||
"name" = regexp_replace("name", '&', '&', 'g'), | ||
"question" = regexp_replace(question::text, '&', '&', 'g')::jsonb | ||
WHERE "name" LIKE '%&%' OR (question->>'en' LIKE '%&%' OR question->>'fr' LIKE '%&%'); | ||
""" | ||
|
||
UPDATE_FLOW_SQL = """ | ||
UPDATE flows | ||
SET | ||
"name" = regexp_replace("name", '&', '&', 'g'), | ||
"description" = regexp_replace(description::text, '&', '&', 'g')::jsonb | ||
WHERE "name" LIKE '%&%' OR (description->>'en' LIKE '%&%' OR description->>'fr' LIKE '%&%'); | ||
""" | ||
|
||
UPDATE_FLOW_HISTORY__SQL = """ | ||
UPDATE flow_histories | ||
SET | ||
"name" = regexp_replace("name", '&', '&', 'g'), | ||
"description" = regexp_replace(description::text, '&', '&', 'g')::jsonb | ||
WHERE "name" LIKE '%&%' OR (description->>'en' LIKE '%&%' OR description->>'fr' LIKE '%&%'); | ||
""" | ||
|
||
QUERIES = [ | ||
UPDATE_APPLET_SQL, | ||
UPDATE_APPLET_HISTORY_SQL, | ||
UPDATE_ACTIVITY_SQL, | ||
UPDATE_ACTIVITY_HISTORY_SQL, | ||
UPDATE_ACTIVITY_SCORES_AND_REPORTS_SQL, | ||
UPDATE_ACTIVITY_HISTORY_SCORES_AND_REPORTS_SQL, | ||
UPDATE_ACTIVITY_ITEM_SQL, | ||
UPDATE_ACTIVITY_ITEM_HISTORY_SQL, | ||
UPDATE_FLOW_SQL, | ||
UPDATE_FLOW_HISTORY__SQL, | ||
] | ||
|
||
|
||
async def main(session: AsyncSession, *args, **kwargs): | ||
try: | ||
for sql in QUERIES: | ||
await session.execute(sql) | ||
await session.commit() | ||
except Exception as ex: | ||
await session.rollback() | ||
raise ex |
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