]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Backpatch: Fix tsvector_out() and tsquery_out() to escape backslesh, add test of...
authorTeodor Sigaev <teodor@sigaev.ru>
Fri, 16 Nov 2007 17:03:15 +0000 (17:03 +0000)
committerTeodor Sigaev <teodor@sigaev.ru>
Fri, 16 Nov 2007 17:03:15 +0000 (17:03 +0000)
Patch by Bruce Momjian <bruce@momjian.us>

contrib/tsearch2/expected/tsearch2.out
contrib/tsearch2/query.c
contrib/tsearch2/sql/tsearch2.sql
contrib/tsearch2/tsvector.c

index 926bc3ad1afbc7afc1d1e35b84dd0b92508b4533..f069fec5121d2901b8f04cf91d459fd177cf8e1d 100644 (file)
@@ -331,6 +331,12 @@ SELECT '''the wether'':dc & '' sKies '':BC & a:d b:a';
  'the wether':dc & ' sKies ':BC & a:d b:a
 (1 row)
 
+SELECT tsvector_in(tsvector_out($$'\\as' ab\c ab\\c AB\\\c ab\\\\c$$::tsvector)), tsquery_in(tsquery_out($$'\\as'$$::tsquery));
+              tsvector_in               | tsquery_in 
+----------------------------------------+------------
+ '\\as' 'abc' 'AB\\c' 'ab\\c' 'ab\\\\c' | '\\as'
+(1 row)
+
 select 'a' < 'b & c'::tsquery;
  ?column? 
 ----------
index 37f60caf1addf2b5a6c9dd37a852838ffbde9556..c86169874cbfd77dbde43dcccba81e011110e031 100644 (file)
@@ -765,6 +765,11 @@ infix(INFIX * in, bool first)
                                *(in->cur) = '\'';
                                in->cur++;
                        }
+                       else if (t_iseq(op, '\\'))
+                       {
+                               *(in->cur) = '\\';
+                               in->cur++;
+                       }
                        COPYCHAR(in->cur, op);
 
                        clen = pg_mblen(op);
index c6ed880b473cb48cdd29c6322808a37ecd8d7dd5..27b29661d27e6ddab3862f657fe3a6e3aef0a863 100644 (file)
@@ -67,6 +67,8 @@ SELECT '1&(2&(4&(5|!6)))'::tsquery;
 SELECT E'1&(''2''&('' 4''&(\\|5 | ''6 \\'' !|&'')))'::tsquery;
 SELECT '''the wether'':dc & '' sKies '':BC & a:d b:a';
 
+SELECT tsvector_in(tsvector_out($$'\\as' ab\c ab\\c AB\\\c ab\\\\c$$::tsvector)), tsquery_in(tsquery_out($$'\\as'$$::tsquery));
+
 select 'a' < 'b & c'::tsquery;
 select 'a' > 'b & c'::tsquery;
 select 'a | f' < 'b & c'::tsquery;
index 059a247f18625db2579af436a7f948fda719ea04..ac8923d8dac4bbfd7f3190d4e090e33874a23d11 100644 (file)
@@ -550,6 +550,14 @@ tsvector_out(PG_FUNCTION_ARGS)
                                curout = outbuf + pos;
                                *curout++ = '\'';
                        }
+                       else if (t_iseq(curin, '\\'))
+                       {
+                               int4            pos = curout - outbuf;
+
+                               outbuf = (char *) repalloc((void *) outbuf, ++lenbuf);
+                               curout = outbuf + pos;
+                               *curout++ = '\\';
+                       }
                        while (len--)
                                *curout++ = *curin++;
                }