summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeodor Sigaev2007-11-16 17:17:52 +0000
committerTeodor Sigaev2007-11-16 17:17:52 +0000
commit4fc32d5891e1e0a6e28248cf29b8bb58e82282ee (patch)
tree000c4779e7de378f8ff3468f4702ae9451d439e4
parentd38814675e6f170544a8ddfd6bff0cfc5b09517a (diff)
Backpatch: Fix tsvector_out() and tsquery_out() to escape backslesh, add test of that.
Patch by Bruce Momjian <bruce@momjian.us>
-rw-r--r--contrib/tsearch2/expected/tsearch2.out6
-rw-r--r--contrib/tsearch2/query.c2
-rw-r--r--contrib/tsearch2/sql/tsearch2.sql2
-rw-r--r--contrib/tsearch2/tsvector.c2
4 files changed, 10 insertions, 2 deletions
diff --git a/contrib/tsearch2/expected/tsearch2.out b/contrib/tsearch2/expected/tsearch2.out
index bdc0f639e25..78c12c52354 100644
--- a/contrib/tsearch2/expected/tsearch2.out
+++ b/contrib/tsearch2/expected/tsearch2.out
@@ -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
-----------------
diff --git a/contrib/tsearch2/query.c b/contrib/tsearch2/query.c
index 2e501210274..532a867be76 100644
--- a/contrib/tsearch2/query.c
+++ b/contrib/tsearch2/query.c
@@ -683,7 +683,7 @@ infix(INFIX * in, bool first)
in->cur++;
while (*op)
{
- if (*op == '\'')
+ if (*op == '\'' || *op == '\\')
{
*(in->cur) = '\\';
in->cur++;
diff --git a/contrib/tsearch2/sql/tsearch2.sql b/contrib/tsearch2/sql/tsearch2.sql
index d6192579ff6..54895d00ccc 100644
--- a/contrib/tsearch2/sql/tsearch2.sql
+++ b/contrib/tsearch2/sql/tsearch2.sql
@@ -65,6 +65,8 @@ SELECT '1&(2&(4&(5|!6)))'::tsquery;
SELECT '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');
diff --git a/contrib/tsearch2/tsvector.c b/contrib/tsearch2/tsvector.c
index 6570ac4e393..19974afc404 100644
--- a/contrib/tsearch2/tsvector.c
+++ b/contrib/tsearch2/tsvector.c
@@ -521,7 +521,7 @@ tsvector_out(PG_FUNCTION_ARGS)
j = ptr->len;
while (j--)
{
- if (*curin == '\'')
+ if (*curin == '\'' || *curin == '\\')
{
int4 pos = curout - outbuf;