aboutsummaryrefslogtreecommitdiffstats
path: root/db/postgres/strip_ascii_escape.pgsql
diff options
context:
space:
mode:
Diffstat (limited to 'db/postgres/strip_ascii_escape.pgsql')
-rw-r--r--db/postgres/strip_ascii_escape.pgsql16
1 files changed, 16 insertions, 0 deletions
diff --git a/db/postgres/strip_ascii_escape.pgsql b/db/postgres/strip_ascii_escape.pgsql
new file mode 100644
index 0000000..00714f6
--- /dev/null
+++ b/db/postgres/strip_ascii_escape.pgsql
@@ -0,0 +1,16 @@
+create or replace function strip_ascii_escape() returns trigger
+language plpgsql as $$
+ begin
+ NEW.log = regexp_replace(NEW.log,'\x1b\[[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]','','g');
+ NEW.log = regexp_replace(NEW.log,'\x1b[PX^_].*?\x1b\\','','g');
+ NEW.log = regexp_replace(NEW.log,'\x1b\][^\a]*(?:\a|\x1b\\)','','g');
+ NEW.log = regexp_replace(NEW.log,'\x1b[\[\]A-Z\\^_@]','','g');
+ NEW.log = regexp_replace(NEW.log,'[\x00-\x1f\x7f-\x9f\xad]+','','g');
+
+ return NEW;
+ end;
+$$;
+
+create trigger strip_ascii_escape
+before insert on public.logs
+for each row execute function strip_ascii_escape()