From 4fc32d5891e1e0a6e28248cf29b8bb58e82282ee Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Fri, 16 Nov 2007 17:17:52 +0000 Subject: [PATCH] Backpatch: Fix tsvector_out() and tsquery_out() to escape backslesh, add test of that. Patch by Bruce Momjian --- contrib/tsearch2/expected/tsearch2.out | 6 ++++++ contrib/tsearch2/query.c | 2 +- contrib/tsearch2/sql/tsearch2.sql | 2 ++ contrib/tsearch2/tsvector.c | 2 +- 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; -- 2.39.5