Skip to content

Commit

Permalink
Fixed CORE-6158 - substring similar - extra characters in the result …
Browse files Browse the repository at this point in the history
…for non latin characters.
  • Loading branch information
asfernandes committed Oct 17, 2019
1 parent 21b8478 commit 6203f07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/dsql/ExprNodes.cpp
Expand Up @@ -11895,18 +11895,17 @@ dsc* SubstringSimilarNode::execute(thread_db* tdbb, jrd_req* request) const

if (evaluator->result())
{
// Get the byte bounds of the matched substring.
unsigned start = 0;
unsigned length = 0;
// Get the character bounds of the matched substring.
unsigned start, length;
evaluator->getResultInfo(&start, &length);

dsc desc;
desc.makeText((USHORT) exprLen, textType);
EVL_make_value(tdbb, &desc, impure);

// And return it.
memcpy(impure->vlu_desc.dsc_address, exprStr + start, length);
impure->vlu_desc.dsc_length = length;
impure->vlu_desc.dsc_length = charSet->substring(exprLen, exprStr,
impure->vlu_desc.dsc_length, impure->vlu_desc.dsc_address,
start, length);

return &impure->vlu_desc;
}
Expand Down
13 changes: 12 additions & 1 deletion src/jrd/Collation.cpp
Expand Up @@ -311,7 +311,18 @@ class Re2SubstringSimilarMatcher : public BaseSubstringSimilarMatcher
if (textType->getAttributes() & TEXTTYPE_ATTR_ACCENT_INSENSITIVE)
UnicodeUtil::utf8Normalize(*bufferPtr);

return regex->matches((const char*) bufferPtr->begin(), bufferPtr->getCount(), &resultStart, &resultLength);
if (!regex->matches((const char*) bufferPtr->begin(), bufferPtr->getCount(), &resultStart, &resultLength))
return false;

if (charSetId != CS_NONE && charSetId != CS_BINARY)
{
// Get the character positions in the utf-8 string.
auto utf8CharSet = IntlUtil::getUtf8CharSet();
resultLength = utf8CharSet->length(resultLength, bufferPtr->begin() + resultStart, true);
resultStart = utf8CharSet->length(resultStart, bufferPtr->begin(), true);
}

return true;
}

virtual void getResultInfo(unsigned* start, unsigned* length)
Expand Down

0 comments on commit 6203f07

Please sign in to comment.