1
0
Fork 0

issue #8137: NULL input field generates U_ILLEGAL_ARGUMENT_ERROR (#8140)

This commit is contained in:
Jan 2019-02-12 17:56:01 +01:00 committed by GitHub
parent 98b024d787
commit a911ea64bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 13 deletions

View File

@ -2021,12 +2021,18 @@ AqlValue Functions::Substitute(ExpressionContext* expressionContext,
arangodb::velocypack::ValueLength length;
char const* str = it.key.getString(length);
matchPatterns.push_back(UnicodeString(str, static_cast<int32_t>(length)));
if (!it.value.isString()) {
if (it.value.isNull()) {
// null replacement value => replace with an empty string
replacePatterns.push_back(UnicodeString("", int32_t(0)));
} else if (it.value.isString()) {
// string case
str = it.value.getStringUnchecked(length);
replacePatterns.push_back(UnicodeString(str, static_cast<int32_t>(length)));
} else {
// non strings
::registerInvalidArgumentWarning(expressionContext, AFN);
return AqlValue(AqlValueHintNull());
}
str = it.value.getStringUnchecked(length);
replacePatterns.push_back(UnicodeString(str, static_cast<int32_t>(length)));
}
} else {
if (parameters.size() < 2) {
@ -2040,13 +2046,14 @@ AqlValue Functions::Substitute(ExpressionContext* expressionContext,
VPackSlice slice = materializer.slice(search, false);
if (search.isArray()) {
for (auto const& it : VPackArrayIterator(slice)) {
if (!it.isString()) {
if (it.isString()) {
arangodb::velocypack::ValueLength length;
char const* str = it.getStringUnchecked(length);
matchPatterns.push_back(UnicodeString(str, static_cast<int32_t>(length)));
} else {
::registerInvalidArgumentWarning(expressionContext, AFN);
return AqlValue(AqlValueHintNull());
}
arangodb::velocypack::ValueLength length;
char const* str = it.getStringUnchecked(length);
matchPatterns.push_back(UnicodeString(str, static_cast<int32_t>(length)));
}
} else {
if (!search.isString()) {
@ -2063,13 +2070,17 @@ AqlValue Functions::Substitute(ExpressionContext* expressionContext,
VPackSlice rslice = materializer2.slice(replace, false);
if (replace.isArray()) {
for (auto const& it : VPackArrayIterator(rslice)) {
if (!it.isString()) {
if (it.isNull()) {
// null replacement value => replace with an empty string
replacePatterns.push_back(UnicodeString("", int32_t(0)));
} else if (it.isString()) {
arangodb::velocypack::ValueLength length;
char const* str = it.getString(length);
replacePatterns.push_back(UnicodeString(str, static_cast<int32_t>(length)));
} else {
::registerInvalidArgumentWarning(expressionContext, AFN);
return AqlValue(AqlValueHintNull());
}
arangodb::velocypack::ValueLength length;
char const* str = it.getString(length);
replacePatterns.push_back(UnicodeString(str, static_cast<int32_t>(length)));
}
} else if (replace.isString()) {
// If we have a string as replacement,

View File

@ -1191,7 +1191,9 @@ function ahuacatlStringFunctionsTestSuite () {
[ 'aaaayyybccc', 'aaaabbbbccc', [ 'A', 'b', 'c' ], [ 'x', 'y', 'z' ], 3 ],
[ 'the quick foxx', 'the quick brown foxx', 'brown' ],
[ 'the quick brown foxx', 'the quick brown foxx', [ ] ],
[ 'the quick foxx', 'the quick brown foxx', [ 'brown' ], [ ] ]
[ 'the quick foxx', 'the quick brown foxx', [ 'brown' ], [ ] ],
[ 'the ant', 'the quick brown foxx', [ 'quick', 'brown', 'foxx' ], [ '', null, 'ant' ] ],
[ 'the ant', 'the quick brown foxx', { quick: '', brown: null, foxx: 'ant' } ],
];
values.forEach(function (value) {
@ -1206,7 +1208,7 @@ function ahuacatlStringFunctionsTestSuite () {
assertEqual([ expected ], nuResults, value);
});
},
// //////////////////////////////////////////////////////////////////////////////
// / @brief test substitute function
// //////////////////////////////////////////////////////////////////////////////