Skip to content

Commit 8ae8a10

Browse files
authored
[Test] Don't include '*' in glob pattern literals (#133114)
This changes the random patterns that are generated inside `GlobTests` to not generate `*` characters when a literal string is intended
1 parent fc300cc commit 8ae8a10

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

libs/core/src/test/java/org/elasticsearch/core/GlobTests.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void testMatchLiteral() {
3030
str = randomAlphanumericOfLength(randomIntBetween(1, 12));
3131
assertMatch(str, str);
3232

33-
str = randomAsciiString(randomIntBetween(1, 24), ch -> ch >= ' ' && ch <= '~' && ch != '*');
33+
str = randomAsciiStringNoAsterisks(randomIntBetween(1, 24));
3434
assertMatch(str, str);
3535
}
3636

@@ -67,7 +67,7 @@ public void testPrefixMatch() {
6767
assertNonMatch("123*", "abc123");
6868
assertNonMatch("123*", "abc123def");
6969

70-
var prefix = randomAsciiString(randomIntBetween(2, 12));
70+
var prefix = randomAsciiStringNoAsterisks(randomIntBetween(2, 12));
7171
var pattern = prefix + "*";
7272
assertMatch(pattern, prefix);
7373
assertMatch(pattern, prefix + randomAsciiString(randomIntBetween(1, 30)));
@@ -92,7 +92,7 @@ public void testSuffixMatch() {
9292
assertNonMatch("*123", "123abc");
9393
assertNonMatch("*123", "abc123def");
9494

95-
var suffix = randomAsciiString(randomIntBetween(2, 12));
95+
var suffix = randomAsciiStringNoAsterisks(randomIntBetween(2, 12));
9696
var pattern = "*" + suffix;
9797
assertMatch(pattern, suffix);
9898
assertMatch(pattern, randomAsciiString(randomIntBetween(1, 30)) + suffix);
@@ -114,7 +114,7 @@ public void testInfixStringMatch() {
114114
assertNonMatch("*123*", "12*");
115115
assertNonMatch("*123*", "1.2.3");
116116

117-
var infix = randomAsciiString(randomIntBetween(2, 12));
117+
var infix = randomAsciiStringNoAsterisks(randomIntBetween(2, 12));
118118
var pattern = "*" + infix + "*";
119119
assertMatch(pattern, infix);
120120
assertMatch(pattern, randomAsciiString(randomIntBetween(1, 30)) + infix + randomAsciiString(randomIntBetween(1, 30)));
@@ -138,8 +138,8 @@ public void testInfixAsteriskMatch() {
138138
assertMatch("123*321", "12345678987654321");
139139
assertNonMatch("123*321", "12321");
140140

141-
var prefix = randomAsciiString(randomIntBetween(2, 12));
142-
var suffix = randomAsciiString(randomIntBetween(2, 12));
141+
var prefix = randomAsciiStringNoAsterisks(randomIntBetween(2, 12));
142+
var suffix = randomAsciiStringNoAsterisks(randomIntBetween(2, 12));
143143
var pattern = prefix + "*" + suffix;
144144
assertMatch(pattern, prefix + suffix);
145145
assertMatch(pattern, prefix + randomAsciiString(randomIntBetween(1, 30)) + suffix);
@@ -180,6 +180,10 @@ private String randomAsciiString(int length) {
180180
return randomAsciiString(length, ch -> ch >= ' ' && ch <= '~');
181181
}
182182

183+
private String randomAsciiStringNoAsterisks(final int length) {
184+
return randomAsciiString(length, ch -> ch >= ' ' && ch <= '~' && ch != '*');
185+
}
186+
183187
private String randomAsciiString(int length, CharPredicate validCharacters) {
184188
StringBuilder str = new StringBuilder(length);
185189
nextChar: for (int i = 0; i < length; i++) {

0 commit comments

Comments
 (0)