aboutsummaryrefslogtreecommitdiffstats
path: root/db/postgres/strip_ascii_escape.pgsql
blob: 00714f6416fab18488204585d28c721b420b3e77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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()