-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[TEST] Fixes to StringMatcherTests #88046
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
[TEST] Fixes to StringMatcherTests #88046
Conversation
Under some seeds (e.g. 3C93AEF7628D6611) prefix2 would start with prefix1, which would mean that input that was intended to test against prefix2 would actually match prefix1 Resolves: elastic#88024
In Hamcest there is now randomFrom(char[]) so this code: randomFrom( "abc".toCharArray() ) will be treated as randomFrom( new Object[] { new char[] { 'a', 'b', 'c' } } ) and will return a char[] The existing code that was intending to return a random char, was actually returning a char[] and then stringifying that into something like [C@5e67f506
Pinging @elastic/es-security (Team:Security) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch(es)!
); | ||
|
||
final List<Character> nonAlpha = "@/#$0123456789()[]{}<>;:%&".chars() | ||
.mapToObj(c -> Character.valueOf((char) c)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional nit: I think boxing happens automatically here, i.e., c -> (char) c)
is sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would, though I think explicit is preferable in this case.
I guess it's just going to come down to personal preference, but I like the clarity of the explicit boxing.
This commit fixes two issues with StringMatcherTests **Problem 1** Under some seeds (e.g. 3C93AEF7628D6611) prefix2 would start with the same text as prefix1. This would mean that input that was intended to test against prefix2 would actually match prefix1, and violate the expectations of the test **Problem 2** The code had the equivalent of randomFrom( "abc".toCharArray() ) But Hamcest does not have a randomFrom(char[]) method, so this code was treated as randomFrom( new Object[] { new char[] { 'a', 'b', 'c' } } ) and will return a char[]. Tests that were written assuming they had a random character, actually had an array (char[]) and would then stringify that object into something like [C@5e67f506 Resolves: elastic#88024
💚 Backport successful
|
This commit fixes two issues with StringMatcherTests **Problem 1** Under some seeds (e.g. 3C93AEF7628D6611) prefix2 would start with the same text as prefix1. This would mean that input that was intended to test against prefix2 would actually match prefix1, and violate the expectations of the test **Problem 2** The code had the equivalent of randomFrom( "abc".toCharArray() ) But Hamcest does not have a randomFrom(char[]) method, so this code was treated as randomFrom( new Object[] { new char[] { 'a', 'b', 'c' } } ) and will return a char[]. Tests that were written assuming they had a random character, actually had an array (char[]) and would then stringify that object into something like [C@5e67f506 Resolves: #88024
This commit fixes two issues with StringMatcherTests
Problem 1
Under some seeds (e.g. 3C93AEF7628D6611) prefix2 would start
with the same text as prefix1. This would mean that input that was
intended to test against prefix2 would actually match prefix1, and
violate the expectations of the test
Problem 2
The code had the equivalent of
But Hamcest does not have a randomFrom(char[]) method, so this
code was treated as
and will return a char[]. Tests that were written assuming they had
a random character, actually had an array (char[]) and would then
stringify that object into something like
Resolves: #88024