Skip to content

Commit ba58563

Browse files
committed
chore: Small refactorings to improves readability and maintainability
1 parent 9847bf6 commit ba58563

File tree

4 files changed

+35
-43
lines changed

4 files changed

+35
-43
lines changed

src/main/java/com/endava/cats/args/FilterArguments.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public List<String> getFirstPhaseFuzzersForPath() {
325325

326326
fuzzersToBeRun = fuzzersToBeRun.stream()
327327
.filter(fuzzer -> !secondPhaseFuzzers.contains(fuzzer))
328-
.collect(Collectors.toList());
328+
.toList();
329329
}
330330

331331
return fuzzersToBeRun;
@@ -420,7 +420,7 @@ private List<String> constructFuzzersListFromCheckArguments() {
420420
finalList.addAll(this.filterFuzzersByAnnotationWhenCheckArgumentSupplied(checkArguments.isCheckHttp(), HttpFuzzer.class));
421421

422422
if (finalList.isEmpty()) {
423-
finalList = fuzzers.stream().map(Object::toString).collect(Collectors.toList());
423+
finalList = fuzzers.stream().map(Object::toString).toList();
424424
}
425425

426426
this.removeIfNotSupplied(checkArguments.isIncludeControlChars(), ControlCharFuzzer.class, finalList);

src/main/java/com/endava/cats/generator/simple/StringGenerator.java

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -284,54 +284,46 @@ public static String cleanPattern(String pattern) {
284284
}
285285

286286
private static String removeMisplacedDollarSigns(String regex) {
287-
StringBuilder result = new StringBuilder();
287+
StringBuilder result = new StringBuilder(regex.length());
288288
boolean inCharClass = false;
289-
boolean escapeNext = false;
290-
int parenDepth = 0; // Tracks depth of parentheses
289+
int parenDepth = 0;
291290
int length = regex.length();
292291

293292
for (int i = 0; i < length; i++) {
294293
char c = regex.charAt(i);
295294

296-
if (escapeNext) {
297-
// Current character is escaped; add it and reset escape flag
298-
result.append(c);
299-
escapeNext = false;
300-
} else if (c == '\\') {
301-
// Next character is escaped
302-
result.append(c);
303-
escapeNext = true;
304-
} else if (c == '[') {
305-
// Entering character class
306-
result.append(c);
307-
inCharClass = true;
308-
} else if (c == ']') {
309-
// Exiting character class
310-
result.append(c);
311-
inCharClass = false;
312-
} else if (c == '(') {
313-
// Entering parentheses group
314-
result.append(c);
315-
parenDepth++;
316-
} else if (c == ')') {
317-
// Exiting parentheses group
318-
result.append(c);
319-
if (parenDepth > 0) {
320-
parenDepth--;
321-
}
322-
} else if (c == '$') {
323-
if (i == length - 1) {
324-
// Dollar sign at the end; keep it
295+
switch (c) {
296+
case '\\':
325297
result.append(c);
326-
} else if (inCharClass) {
327-
// Dollar sign inside character class; keep it
298+
if (i + 1 < length) {
299+
result.append(regex.charAt(++i));
300+
}
301+
break;
302+
case '[':
303+
inCharClass = true;
328304
result.append(c);
329-
} else if (parenDepth > 0) {
330-
// Dollar sign inside parentheses; keep it
305+
break;
306+
case ']':
307+
inCharClass = false;
308+
result.append(c);
309+
break;
310+
case '(':
311+
parenDepth++;
312+
result.append(c);
313+
break;
314+
case ')':
315+
if (parenDepth > 0) {
316+
parenDepth--;
317+
}
318+
result.append(c);
319+
break;
320+
case '$':
321+
if (i == length - 1 || inCharClass || parenDepth > 0) {
322+
result.append(c);
323+
}
324+
break;
325+
default:
331326
result.append(c);
332-
}
333-
} else {
334-
result.append(c);
335327
}
336328
}
337329
return result.toString();

src/main/java/com/endava/cats/model/generator/OpenAPIModelGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ int getArrayLength(Schema<?> property) {
431431
int min = null == property.getMinItems() ? 1 : property.getMinItems();
432432
int max = null == property.getMaxItems() ? 2 : property.getMaxItems();
433433

434-
return Math.max(min, Math.min(this.arraySize, max));
434+
return Math.clamp(this.arraySize, min, max);
435435
}
436436

437437
double randomNumber(Double min, Double max) {

src/main/java/com/endava/cats/util/DepthLimitingSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* to exceed the maximum size that Jackson can serialize without streaming.
1717
*/
1818
public class DepthLimitingSerializer extends JsonSerializer<Object> {
19-
private static int maxDepth;
19+
private final int maxDepth;
2020
private final ObjectMapper mapper = new ObjectMapper();
2121
private final ThreadLocal<Integer> currentDepth = ThreadLocal.withInitial(() -> 0);
2222

0 commit comments

Comments
 (0)