Skip to content

Commit 892a8d0

Browse files
committed
Add forgotten PL/Perl regression test files
Due to a git hook blowing up in my face telling me I could not commit Peter Eisentraut's patch on his name, I had to "git reset" to fix the previous commit ... and then forgot that I needed to "git add" these files :-(
1 parent fc661f7 commit 892a8d0

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

src/pl/plperl/expected/plperl_lc.out

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--
2+
-- Make sure strings are validated
3+
-- Should fail for all encodings, as nul bytes are never permitted.
4+
--
5+
CREATE OR REPLACE FUNCTION perl_zerob() RETURNS TEXT AS $$
6+
return "abcd\0efg";
7+
$$ LANGUAGE plperl;
8+
SELECT perl_zerob();
9+
ERROR: invalid byte sequence for encoding "UTF8": 0x00
10+
CONTEXT: PL/Perl function "perl_zerob"
11+
CREATE OR REPLACE FUNCTION perl_0x80_in(text) RETURNS BOOL AS $$
12+
return ($_[0] eq "abc\x80de" ? "true" : "false");
13+
$$ LANGUAGE plperl;
14+
SELECT perl_0x80_in(E'abc\x80de');
15+
ERROR: invalid byte sequence for encoding "UTF8": 0x80
16+
CREATE OR REPLACE FUNCTION perl_0x80_out() RETURNS TEXT AS $$
17+
return "abc\x80de";
18+
$$ LANGUAGE plperl;
19+
SELECT perl_0x80_out() = E'abc\x80de';
20+
ERROR: invalid byte sequence for encoding "UTF8": 0x80
21+
CREATE OR REPLACE FUNCTION perl_utf_inout(text) RETURNS TEXT AS $$
22+
$str = $_[0]; $code = "NotUTF8:"; $match = "ab\xe5\xb1\xb1cd";
23+
if (utf8::is_utf8($str)) {
24+
$code = "UTF8:"; utf8::decode($str); $match="ab\x{5c71}cd";
25+
}
26+
return ($str ne $match ? $code."DIFFER" : $code."ab\x{5ddd}cd");
27+
$$ LANGUAGE plperl;
28+
SELECT encode(perl_utf_inout(E'ab\xe5\xb1\xb1cd')::bytea, 'escape')
29+
encode
30+
-----------------------
31+
UTF8:ab\345\267\235cd
32+
(1 row)
33+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--
2+
-- Make sure strings are validated
3+
-- Should fail for all encodings, as nul bytes are never permitted.
4+
--
5+
CREATE OR REPLACE FUNCTION perl_zerob() RETURNS TEXT AS $$
6+
return "abcd\0efg";
7+
$$ LANGUAGE plperl;
8+
SELECT perl_zerob();
9+
ERROR: invalid byte sequence for encoding "SQL_ASCII": 0x00
10+
CONTEXT: PL/Perl function "perl_zerob"
11+
CREATE OR REPLACE FUNCTION perl_0x80_in(text) RETURNS BOOL AS $$
12+
return ($_[0] eq "abc\x80de" ? "true" : "false");
13+
$$ LANGUAGE plperl;
14+
SELECT perl_0x80_in(E'abc\x80de');
15+
perl_0x80_in
16+
--------------
17+
t
18+
(1 row)
19+
20+
CREATE OR REPLACE FUNCTION perl_0x80_out() RETURNS TEXT AS $$
21+
return "abc\x80de";
22+
$$ LANGUAGE plperl;
23+
SELECT perl_0x80_out() = E'abc\x80de';
24+
?column?
25+
----------
26+
t
27+
(1 row)
28+
29+
CREATE OR REPLACE FUNCTION perl_utf_inout(text) RETURNS TEXT AS $$
30+
$str = $_[0]; $code = "NotUTF8:"; $match = "ab\xe5\xb1\xb1cd";
31+
if (utf8::is_utf8($str)) {
32+
$code = "UTF8:"; utf8::decode($str); $match="ab\x{5c71}cd";
33+
}
34+
return ($str ne $match ? $code."DIFFER" : $code."ab\x{5ddd}cd");
35+
$$ LANGUAGE plperl;
36+
SELECT encode(perl_utf_inout(E'ab\xe5\xb1\xb1cd')::bytea, 'escape')
37+
encode
38+
--------------------------
39+
NotUTF8:ab\345\267\235cd
40+
(1 row)
41+

src/pl/plperl/sql/plperl_lc.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--
2+
-- Make sure strings are validated
3+
-- Should fail for all encodings, as nul bytes are never permitted.
4+
--
5+
CREATE OR REPLACE FUNCTION perl_zerob() RETURNS TEXT AS $$
6+
return "abcd\0efg";
7+
$$ LANGUAGE plperl;
8+
SELECT perl_zerob();
9+
CREATE OR REPLACE FUNCTION perl_0x80_in(text) RETURNS BOOL AS $$
10+
return ($_[0] eq "abc\x80de" ? "true" : "false");
11+
$$ LANGUAGE plperl;
12+
SELECT perl_0x80_in(E'abc\x80de');
13+
CREATE OR REPLACE FUNCTION perl_0x80_out() RETURNS TEXT AS $$
14+
return "abc\x80de";
15+
$$ LANGUAGE plperl;
16+
SELECT perl_0x80_out() = E'abc\x80de';
17+
CREATE OR REPLACE FUNCTION perl_utf_inout(text) RETURNS TEXT AS $$
18+
$str = $_[0]; $code = "NotUTF8:"; $match = "ab\xe5\xb1\xb1cd";
19+
if (utf8::is_utf8($str)) {
20+
$code = "UTF8:"; utf8::decode($str); $match="ab\x{5c71}cd";
21+
}
22+
return ($str ne $match ? $code."DIFFER" : $code."ab\x{5ddd}cd");
23+
$$ LANGUAGE plperl;
24+
SELECT encode(perl_utf_inout(E'ab\xe5\xb1\xb1cd')::bytea, 'escape')

0 commit comments

Comments
 (0)