Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita867b40

Browse files
committed
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
1 parent2f1e7ff commita867b40

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

‎src/backend/utils/adt/tsquery.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.10 2007/11/15 22:25:16 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.11 2007/11/16 15:05:59 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -614,6 +614,11 @@ infix(INFIX *in, bool first)
614614
*(in->cur)='\'';
615615
in->cur++;
616616
}
617+
elseif (t_iseq(op,'\\'))
618+
{
619+
*(in->cur)='\\';
620+
in->cur++;
621+
}
617622
COPYCHAR(in->cur,op);
618623

619624
clen=pg_mblen(op);

‎src/backend/utils/adt/tsvector.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector.c,v 1.8 2007/11/15 22:25:16 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector.c,v 1.9 2007/11/16 15:05:59 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -345,6 +345,8 @@ tsvectorout(PG_FUNCTION_ARGS)
345345

346346
if (t_iseq(curin,'\''))
347347
*curout++='\'';
348+
elseif (t_iseq(curin,'\\'))
349+
*curout++='\\';
348350

349351
while (len--)
350352
*curout++=*curin++;

‎src/test/regress/expected/tstypes.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ SELECT E'''1 \\''2'' '' 3'' 4 '::tsvector;
5959
'4' ' 3' '1 ''2'
6060
(1 row)
6161

62+
SELECT $$'\\as' ab\c ab\\c AB\\\c ab\\\\c$$::tsvector;
63+
tsvector
64+
----------------------------------------
65+
'\\as' 'abc' 'AB\\c' 'ab\\c' 'ab\\\\c'
66+
(1 row)
67+
68+
SELECT tsvectorin(tsvectorout($$'\\as' ab\c ab\\c AB\\\c ab\\\\c$$::tsvector));
69+
tsvectorin
70+
----------------------------------------
71+
'\\as' 'abc' 'AB\\c' 'ab\\c' 'ab\\\\c'
72+
(1 row)
73+
6274
SELECT '''w'':4A,3B,2C,1D,5 a:8';
6375
?column?
6476
-----------------------
@@ -318,6 +330,12 @@ SELECT E'1&(''2''&('' 4''&(\\|5 | ''6 \\'' !|&'')))'::tsquery;
318330
'1' & '2' & ' 4' & ( '|5' | '6 '' !|&' )
319331
(1 row)
320332

333+
SELECT $$'\\as'$$::tsquery;
334+
tsquery
335+
---------
336+
'\\as'
337+
(1 row)
338+
321339
SELECT 'a' < 'b & c'::tsquery as "true";
322340
true
323341
------

‎src/test/regress/sql/tstypes.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ SELECT E'''1 \\''2'''::tsvector;
1010
SELECT E'''1\\''2''3'::tsvector;
1111
SELECT E'''1\\''2'' 3'::tsvector;
1212
SELECT E'''1\\''2'''' 3'' 4'::tsvector;
13+
SELECT $$'\\as' ab\c ab\\c AB\\\c ab\\\\c$$::tsvector;
14+
SELECT tsvectorin(tsvectorout($$'\\as' ab\c ab\\c AB\\\c ab\\\\c$$::tsvector));
1315
SELECT'''w'':4A,3B,2C,1D,5 a:8';
1416
SELECT'a:3A b:2a'::tsvector||'ba:1234 a:1B';
1517
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;
5557
SELECT'1&(2&(4&(5|6)))'::tsquery;
5658
SELECT'1&(2&(4&(5|!6)))'::tsquery;
5759
SELECT E'1&(''2''&('' 4''&(\\|5 |''6\\'' !|&'')))'::tsquery;
60+
SELECT $$'\\as'$$::tsquery;
5861

5962
SELECT'a'<'b & c'::tsqueryas"true";
6063
SELECT'a'>'b & c'::tsqueryas"false";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp