mirror of
https://github.com/postgres/postgres.git
synced 2025-04-20 00:42:27 +03:00
Fix tsvectorout() and tsqueryout() to escape backslesh, add test of that.
Patch by Bruce Momjian <bruce@momjian.us> Backpatch is needed, but it's impossible to apply it directly
This commit is contained in:
parent
2f1e7ffb76
commit
a867b40cf4
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.10 2007/11/15 22:25:16 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.11 2007/11/16 15:05:59 teodor Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -614,6 +614,11 @@ infix(INFIX *in, bool first)
|
|||||||
*(in->cur) = '\'';
|
*(in->cur) = '\'';
|
||||||
in->cur++;
|
in->cur++;
|
||||||
}
|
}
|
||||||
|
else if (t_iseq(op, '\\'))
|
||||||
|
{
|
||||||
|
*(in->cur) = '\\';
|
||||||
|
in->cur++;
|
||||||
|
}
|
||||||
COPYCHAR(in->cur, op);
|
COPYCHAR(in->cur, op);
|
||||||
|
|
||||||
clen = pg_mblen(op);
|
clen = pg_mblen(op);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector.c,v 1.8 2007/11/15 22:25:16 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector.c,v 1.9 2007/11/16 15:05:59 teodor Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -345,6 +345,8 @@ tsvectorout(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
if (t_iseq(curin, '\''))
|
if (t_iseq(curin, '\''))
|
||||||
*curout++ = '\'';
|
*curout++ = '\'';
|
||||||
|
else if (t_iseq(curin, '\\'))
|
||||||
|
*curout++ = '\\';
|
||||||
|
|
||||||
while (len--)
|
while (len--)
|
||||||
*curout++ = *curin++;
|
*curout++ = *curin++;
|
||||||
|
@ -59,6 +59,18 @@ SELECT E'''1 \\''2'' '' 3'' 4 '::tsvector;
|
|||||||
'4' ' 3' '1 ''2'
|
'4' ' 3' '1 ''2'
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
SELECT $$'\\as' ab\c ab\\c AB\\\c ab\\\\c$$::tsvector;
|
||||||
|
tsvector
|
||||||
|
----------------------------------------
|
||||||
|
'\\as' 'abc' 'AB\\c' 'ab\\c' 'ab\\\\c'
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT tsvectorin(tsvectorout($$'\\as' ab\c ab\\c AB\\\c ab\\\\c$$::tsvector));
|
||||||
|
tsvectorin
|
||||||
|
----------------------------------------
|
||||||
|
'\\as' 'abc' 'AB\\c' 'ab\\c' 'ab\\\\c'
|
||||||
|
(1 row)
|
||||||
|
|
||||||
SELECT '''w'':4A,3B,2C,1D,5 a:8';
|
SELECT '''w'':4A,3B,2C,1D,5 a:8';
|
||||||
?column?
|
?column?
|
||||||
-----------------------
|
-----------------------
|
||||||
@ -318,6 +330,12 @@ SELECT E'1&(''2''&('' 4''&(\\|5 | ''6 \\'' !|&'')))'::tsquery;
|
|||||||
'1' & '2' & ' 4' & ( '|5' | '6 '' !|&' )
|
'1' & '2' & ' 4' & ( '|5' | '6 '' !|&' )
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
SELECT $$'\\as'$$::tsquery;
|
||||||
|
tsquery
|
||||||
|
---------
|
||||||
|
'\\as'
|
||||||
|
(1 row)
|
||||||
|
|
||||||
SELECT 'a' < 'b & c'::tsquery as "true";
|
SELECT 'a' < 'b & c'::tsquery as "true";
|
||||||
true
|
true
|
||||||
------
|
------
|
||||||
|
@ -10,6 +10,8 @@ SELECT E'''1 \\''2'''::tsvector;
|
|||||||
SELECT E'''1 \\''2''3'::tsvector;
|
SELECT E'''1 \\''2''3'::tsvector;
|
||||||
SELECT E'''1 \\''2'' 3'::tsvector;
|
SELECT E'''1 \\''2'' 3'::tsvector;
|
||||||
SELECT E'''1 \\''2'' '' 3'' 4 '::tsvector;
|
SELECT E'''1 \\''2'' '' 3'' 4 '::tsvector;
|
||||||
|
SELECT $$'\\as' ab\c ab\\c AB\\\c ab\\\\c$$::tsvector;
|
||||||
|
SELECT tsvectorin(tsvectorout($$'\\as' ab\c ab\\c AB\\\c ab\\\\c$$::tsvector));
|
||||||
SELECT '''w'':4A,3B,2C,1D,5 a:8';
|
SELECT '''w'':4A,3B,2C,1D,5 a:8';
|
||||||
SELECT 'a:3A b:2a'::tsvector || 'ba:1234 a:1B';
|
SELECT 'a:3A b:2a'::tsvector || 'ba:1234 a:1B';
|
||||||
SELECT setweight('w:12B w:13* w:12,5,6 a:1,3* a:3 w asd:1dc asd zxc:81,567,222A'::tsvector, 'c');
|
SELECT setweight('w:12B w:13* w:12,5,6 a:1,3* a:3 w asd:1dc asd zxc:81,567,222A'::tsvector, 'c');
|
||||||
@ -55,6 +57,7 @@ SELECT '1&2&4&5&6'::tsquery;
|
|||||||
SELECT '1&(2&(4&(5|6)))'::tsquery;
|
SELECT '1&(2&(4&(5|6)))'::tsquery;
|
||||||
SELECT '1&(2&(4&(5|!6)))'::tsquery;
|
SELECT '1&(2&(4&(5|!6)))'::tsquery;
|
||||||
SELECT E'1&(''2''&('' 4''&(\\|5 | ''6 \\'' !|&'')))'::tsquery;
|
SELECT E'1&(''2''&('' 4''&(\\|5 | ''6 \\'' !|&'')))'::tsquery;
|
||||||
|
SELECT $$'\\as'$$::tsquery;
|
||||||
|
|
||||||
SELECT 'a' < 'b & c'::tsquery as "true";
|
SELECT 'a' < 'b & c'::tsquery as "true";
|
||||||
SELECT 'a' > 'b & c'::tsquery as "false";
|
SELECT 'a' > 'b & c'::tsquery as "false";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user