clean up Expedition parsing regexp;

see https://github.com/SAP/sailing-analytics/security/code-scanning/114
This commit is contained in:
Axel Uhl
2025-01-30 15:33:28 +01:00
parent 253f555c06
commit da578969a8
2 changed files with 13 additions and 2 deletions
@@ -1,6 +1,7 @@
package com.sap.sse.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -65,4 +66,14 @@ public class RegexTest {
logger.info("Escaped value: "+escaped);
assertEquals("\"abc\\\\\\'\\\"\\\\\\\"\"", escaped);
}
@Test
public void testNonExponentialExpeditionPattern() {
final Pattern completeLinePattern = Pattern
.compile("#([0-9]*)((,([0-9][0-9]*),(-?[0-9]*(\\.[0-9]*)?))*)\\*X?([0-9a-fA-F][0-9a-fA-F]*)");
final Matcher m1 = completeLinePattern.matcher("#,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,X");
assertFalse(m1.matches());
final Matcher m2 = completeLinePattern.matcher("#,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,*35");
assertTrue(m2.matches());
}
}