Skip to content

Commit

Permalink
fixed backslash consumed by exception parser at query cause breaks qu…
Browse files Browse the repository at this point in the history
…ery parser; fixed #2851; added regressions to test 334
  • Loading branch information
tomatolog committed Jul 8, 2022
1 parent 1e25ead commit 9692a84
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/tokenizer/tokenizerbase2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ bool CSphTokenizerBase2::CheckException ( const BYTE* pStart, const BYTE* pCur,
{
p++;
continue;
;
}
iNode = m_pExc->GetNext ( iNode, *p++ );
if ( iNode < 0 )
Expand All @@ -274,6 +273,7 @@ bool CSphTokenizerBase2::CheckException ( const BYTE* pStart, const BYTE* pCur,

const BYTE* pMapEnd = nullptr; // the longest exception found so far is [pStart,pMapEnd)
const BYTE* pMapTo = nullptr; // the destination mapping
bool bHasQueryQuote = false;

// now, we got ourselves a valid exception prefix, so lets keep consuming more bytes,
// ie. until further separators, and keep looking for a full exception match
Expand All @@ -283,6 +283,7 @@ bool CSphTokenizerBase2::CheckException ( const BYTE* pStart, const BYTE* pCur,
if ( bQueryMode && *p == '\\' )
{
p++;
bHasQueryQuote = true;
continue;
}

Expand Down Expand Up @@ -332,10 +333,16 @@ bool CSphTokenizerBase2::CheckException ( const BYTE* pStart, const BYTE* pCur,
return false;

strncpy ( (char*)m_sAccum, (char*)const_cast<BYTE*> ( pMapTo ), sizeof ( m_sAccum ) - 1 );
m_pCur = pMapEnd;
m_pTokenStart = pStart;
m_pTokenEnd = pMapEnd;
m_iLastTokenLen = (int)strlen ( (char*)m_sAccum );
if ( bHasQueryQuote )
{
// move backpointer to the head of the quoting sequence
while ( pMapEnd-1>=pStart && *(pMapEnd-1)=='\\' )
pMapEnd--;
}
m_pCur = pMapEnd;
m_pTokenEnd = pMapEnd;

m_bWasSynonym = true;
return true;
Expand Down
1 change: 1 addition & 0 deletions test/test_334/exc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IT => IT
Loading

0 comments on commit 9692a84

Please sign in to comment.