Skip to content

Commit f851392

Browse files
author
Rinat Mukhtarov
committed
url_encode(text) improved
1 parent b852947 commit f851392

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

functions/url_encode.sql

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--see also extension https://github.com/okbob/url_encode with C implementation
22

3-
create or replace function url_encode(text)
3+
create or replace function public.url_encode(text)
44
returns text
55
immutable
6-
strict
6+
strict -- returns null if any parameter is null
77
language sql
88
set search_path = ''
99
as $$
@@ -16,16 +16,13 @@ select
1616
end,
1717
''
1818
)
19-
from (
20-
select char
21-
--from regexp_split_to_table($1, '') as ch
22-
from unnest(string_to_array($1, null)) as char
23-
) as s;
19+
from --regexp_split_to_table($1, '') as s(char) --deprecated
20+
unnest(string_to_array($1, null)) as s(char);
2421
$$;
2522

2623
--TEST
2724
do $$
2825
begin
29-
assert urlencode('hello, привет!') = 'hello%2C%20%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82%21';
26+
assert public.url_encode('hello, привет!') = 'hello%2C%20%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82%21';
3027
end;
3128
$$;

0 commit comments

Comments
 (0)