Backpatch: Fix tsvector_out() and tsquery_out() to escape backslesh, add test of...
authorTeodor Sigaev <[email protected]>
Fri, 16 Nov 2007 17:09:15 +0000 (17:09 +0000)
committerTeodor Sigaev <[email protected]>
Fri, 16 Nov 2007 17:09:15 +0000 (17:09 +0000)
Patch by Bruce Momjian <[email protected]>

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

index cb183918872e555fb7c0d0cd64776058d18f0e48..46498224c4315bbb05cbd9ac19033cb5967a1785 100644 (file)
@@ -342,6 +342,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 lexize('simple', 'ASD56 hsdkf');
      lexize      
 -----------------
index 16f20b23b5df0e12286704d821e65d3039168e7f..29f43c6f067f49a8aa6e5698940f1c94831db6f0 100644 (file)
@@ -723,7 +723,7 @@ infix(INFIX * in, bool first)
                in->cur++;
                while (*op)
                {
-                       if (*op == '\'')
+                       if (*op == '\'' || *op == '\\')
                        {
                                *(in->cur) = '\\';
                                in->cur++;
index 52e709d74b7a36fa5f7b02bb2e947b92b60819ec..563399e3666b36fe7ff717a92c50993f53e8429f 100644 (file)
@@ -65,6 +65,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 lexize('simple', 'ASD56 hsdkf');
 select lexize('en_stem', 'SKIES Problems identity');
 
index e0fc67f2b18507dc45e87b6f6eac3990e5b2efe0..c1d34bad277a0ffcd7fed2fa2ed7324b94894f74 100644 (file)
@@ -520,7 +520,7 @@ tsvector_out(PG_FUNCTION_ARGS)
                j = ptr->len;
                while (j--)
                {
-                       if (*curin == '\'')
+                       if (*curin == '\'' || *curin == '\\')
                        {
                                int4            pos = curout - outbuf;