Skip to content

Commit 0c4f289

Browse files
committed
Use '' rather than \' for literal single quotes in strings in
/contrib/tsearch2. Teodor Sigaev
1 parent 4b636e3 commit 0c4f289

File tree

3 files changed

+43
-28
lines changed

3 files changed

+43
-28
lines changed

contrib/tsearch2/expected/tsearch2.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,25 @@ SELECT '''1 2'''::tsvector;
5959
SELECT E'''1 \\''2'''::tsvector;
6060
tsvector
6161
----------
62-
'1 \'2'
62+
'1 ''2'
6363
(1 row)
6464

6565
SELECT E'''1 \\''2''3'::tsvector;
6666
tsvector
6767
-------------
68-
'3' '1 \'2'
68+
'3' '1 ''2'
6969
(1 row)
7070

7171
SELECT E'''1 \\''2'' 3'::tsvector;
7272
tsvector
7373
-------------
74-
'3' '1 \'2'
74+
'3' '1 ''2'
7575
(1 row)
7676

7777
SELECT E'''1 \\''2'' '' 3'' 4 '::tsvector;
7878
tsvector
7979
------------------
80-
'4' ' 3' '1 \'2'
80+
'4' ' 3' '1 ''2'
8181
(1 row)
8282

8383
select '''w'':4A,3B,2C,1D,5 a:8';
@@ -138,7 +138,7 @@ SELECT '''1 2'''::tsquery;
138138
SELECT E'''1 \\''2'''::tsquery;
139139
tsquery
140140
---------
141-
'1 \'2'
141+
'1 ''2'
142142
(1 row)
143143

144144
SELECT '!1'::tsquery;
@@ -336,7 +336,7 @@ SELECT '1&(2&(4&(5|!6)))'::tsquery;
336336
SELECT E'1&(''2''&('' 4''&(\\|5 | ''6 \\'' !|&'')))'::tsquery;
337337
tsquery
338338
------------------------------------------
339-
'1' & '2' & ' 4' & ( '|5' | '6 \' !|&' )
339+
'1' & '2' & ' 4' & ( '|5' | '6 '' !|&' )
340340
(1 row)
341341

342342
SELECT '''the wether'':dc & '' sKies '':BC & a:d b:a';

contrib/tsearch2/query.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ findoprnd(ITEM * ptr, int4 *pos)
604604
* input
605605
*/
606606
static QUERYTYPE *
607-
queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int cfg_id, bool isplain)
607+
queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int cfg_id, bool isplain)
608608
{
609609
QPRS_STATE state;
610610
int4 i;
@@ -748,7 +748,7 @@ infix(INFIX * in, bool first)
748748
{
749749
if ( t_iseq(op, '\'') )
750750
{
751-
*(in->cur) = '\\';
751+
*(in->cur) = '\'';
752752
in->cur++;
753753
}
754754
COPYCHAR(in->cur,op);

contrib/tsearch2/tsvector.c

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,14 @@ uniqueentry(WordEntryIN * a, int4 l, char *buf, int4 *outbuflen)
164164
return res + 1 - a;
165165
}
166166

167-
#define WAITWORD 1
168-
#define WAITENDWORD 2
167+
#define WAITWORD 1
168+
#define WAITENDWORD 2
169169
#define WAITNEXTCHAR 3
170170
#define WAITENDCMPLX 4
171-
#define WAITPOSINFO 5
172-
#define INPOSINFO 6
171+
#define WAITPOSINFO 5
172+
#define INPOSINFO 6
173173
#define WAITPOSDELIM 7
174+
#define WAITCHARCMPLX 8
174175

175176
#define RESIZEPRSBUF \
176177
do { \
@@ -270,21 +271,8 @@ gettoken_tsvector(TI_IN_STATE * state)
270271
}
271272
else if (state->state == WAITENDCMPLX)
272273
{
273-
if ( t_iseq(state->prsbuf, '\'') )
274-
{
275-
RESIZEPRSBUF;
276-
*(state->curpos) = '\0';
277-
if (state->curpos == state->word)
278-
ereport(ERROR,
279-
(errcode(ERRCODE_SYNTAX_ERROR),
280-
errmsg("syntax error")));
281-
if (state->oprisdelim)
282-
{
283-
state->prsbuf+=pg_mblen(state->prsbuf);
284-
return 1;
285-
}
286-
else
287-
state->state = WAITPOSINFO;
274+
if ( t_iseq(state->prsbuf, '\'') ) {
275+
state->state = WAITCHARCMPLX;
288276
}
289277
else if ( t_iseq(state->prsbuf, '\\') )
290278
{
@@ -302,6 +290,31 @@ gettoken_tsvector(TI_IN_STATE * state)
302290
state->curpos+=pg_mblen(state->prsbuf);
303291
}
304292
}
293+
else if (state->state == WAITCHARCMPLX)
294+
{
295+
if ( t_iseq(state->prsbuf, '\'') )
296+
{
297+
RESIZEPRSBUF;
298+
COPYCHAR(state->curpos, state->prsbuf);
299+
state->curpos+=pg_mblen(state->prsbuf);
300+
state->state = WAITENDCMPLX;
301+
} else {
302+
RESIZEPRSBUF;
303+
*(state->curpos) = '\0';
304+
if (state->curpos == state->word)
305+
ereport(ERROR,
306+
(errcode(ERRCODE_SYNTAX_ERROR),
307+
errmsg("syntax error")));
308+
if (state->oprisdelim)
309+
{
310+
/* state->prsbuf+=pg_mblen(state->prsbuf); */
311+
return 1;
312+
}
313+
else
314+
state->state = WAITPOSINFO;
315+
continue; /* recheck current character */
316+
}
317+
}
305318
else if (state->state == WAITPOSINFO)
306319
{
307320
if ( t_iseq(state->prsbuf, ':') )
@@ -385,6 +398,8 @@ gettoken_tsvector(TI_IN_STATE * state)
385398
else
386399
/* internal error */
387400
elog(ERROR, "internal error");
401+
402+
/* get next char */
388403
state->prsbuf+=pg_mblen(state->prsbuf);
389404
}
390405

@@ -529,7 +544,7 @@ tsvector_out(PG_FUNCTION_ARGS)
529544

530545
outbuf = (char *) repalloc((void *) outbuf, ++lenbuf);
531546
curout = outbuf + pos;
532-
*curout++ = '\\';
547+
*curout++ = '\'';
533548
}
534549
while(len--)
535550
*curout++ = *curin++;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy