/
telnov.ob
/
postgresql-patterns-library
Обзор
Документация
Войти
/
telnov.ob
/
postgresql-patterns-library
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
functions/has_xml.sql
62 строки
2 KB
rin-nas
old pg10 comment removed
13 апр 2026, 11:45
13 апр 2026, 11:45
233b866
Код
Авторство
О чём код?
create or replace function public.has_xml(str text) returns boolean immutable strict -- returns null if any parameter is null parallel safe language plpgsql set search_path = '' cost 2 as $function$ declare xmlCdataOpen text default '<!\[CDATA\['; xmlCdataClose text default '\]\]>'; xmlCommentOpen text default '<!--'; xmlCommentClose text default '-->'; xmlTagAttrs text default $$ (?: [^>"'] | " [^"]* " #attribute value in double quotes | ' [^']* ' #attribute value in single quotes )* $$; xmlTagOpenOrDoctype text default '<!?[a-zA-Z]' || xmlTagAttrs || '>'; xmlTagClose text default '<\/[a-zA-Z][a-zA-Z\d]*>'; xml text default '(?:' || xmlTagOpenOrDoctype || ' | ' || xmlTagClose || ' | ' || xmlCdataOpen || ' .*? ' || xmlCdataClose || ' | ' || xmlCommentOpen || ' .*? ' || xmlCommentClose || ')'; begin --raise notice '%', xml; return octet_length(str) > 2 --speed improves and regexp_match(str, xml, 'sx') is not null; end; $function$; comment on function public.has_xml(text) is 'Checks that the text contains xml or html'; --TEST do $do$ begin --positive assert public.has_xml('<B>'); assert public.has_xml('<br/>'); assert public.has_xml('</a>'); assert public.has_xml($$<a href='#'title="do it">$$); assert public.has_xml('<a href="do.it?a<b&a>c">'); assert public.has_xml('<!-- -->'); assert public.has_xml('<![CDATA[ ]]>'); --negative assert public.has_xml(null) is null; assert not public.has_xml(''); assert not public.has_xml('a<b'); assert not public.has_xml('a>b'); assert not public.has_xml('a < b > c'); assert not public.has_xml('<!--'); assert not public.has_xml('-->'); assert not public.has_xml('<![CDATA['); assert not public.has_xml(']]>'); end $do$;