8000 allow using `RANDOM_TOKEN` AQL function with an argument value of `0`. by jsteemann · Pull Request #10414 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
allow using RANDOM_TOKEN AQL function with an argument value of 0.
  • Loading branch information
jsteemann committed Nov 13, 2019
commit 158d6552f1080dcf2443c20c34c10284982e3712
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions arangod/Aql/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/js/server/aql/aql-functions-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

};
Expand Down
0