1
0
Fork 0

allow using `RANDOM_TOKEN` AQL function with an argument value of `0`. (#10414)

This commit is contained in:
Jan 2019-11-13 22:20:00 +01:00 committed by GitHub
parent 237a3fcf07
commit fd87abc522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View File

@ -1,6 +1,10 @@
devel
-----
* Allow usage of AQL function `RANDOM_TOKEN` with an argument value of `0`. This
now produces an empty string, whereas in older versions this threw an invalid
value exception.
* Add startup option `--rocksdb.exclusive-writes` to avoid write-write conflicts.
This options allows for an easier transition from MMFiles to the RocksDB storage

View File

@ -4250,14 +4250,14 @@ AqlValue Functions::RandomToken(ExpressionContext*, transaction::Methods*,
AqlValue const& value = extractFunctionParameterValue(parameters, 0);
int64_t const length = value.toInt64();
if (length <= 0 || length > 65536) {
if (length < 0 || length > 65536) {
THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH,
"RANDOM_TOKEN");
}
UniformCharacter JSNumGenerator(
UniformCharacter generator(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
return AqlValue(JSNumGenerator.random(static_cast<size_t>(length)));
return AqlValue(generator.random(static_cast<size_t>(length)));
}
/// @brief function MD5

View File

@ -2566,15 +2566,15 @@ function ahuacatlStringFunctionsTestSuite () {
assertQueryError(errors.ERROR_QUERY_FUNCTION_ARGUMENT_NUMBER_MISMATCH.code, 'RETURN RANDOM_TOKEN(1, 2)');
assertQueryError(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, 'RETURN RANDOM_TOKEN(-1)');
assertQueryError(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, 'RETURN RANDOM_TOKEN(-10)');
assertQueryError(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, 'RETURN RANDOM_TOKEN(0)');
assertQueryError(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, 'RETURN RANDOM_TOKEN(65537)');
var actual = getQueryResults('FOR i IN [ 1, 10, 100, 1000 ] RETURN RANDOM_TOKEN(i)');
assertEqual(4, actual.length);
var actual = getQueryResults('FOR i IN [ 1, 10, 100, 1000, 0 ] RETURN RANDOM_TOKEN(i)');
assertEqual(5, actual.length);
assertEqual(1, actual[0].length);
assertEqual(10, actual[1].length);
assertEqual(100, actual[2].length);
assertEqual(1000, actual[3].length);
assertEqual(0, actual[4].length);
}
};