|
10 | 10 | package net.sf.jsqlparser.expression; |
11 | 11 |
|
12 | 12 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 13 | +import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; |
13 | 14 |
|
| 15 | +import java.time.Duration; |
14 | 16 | import net.sf.jsqlparser.JSQLParserException; |
15 | 17 | import net.sf.jsqlparser.statement.select.PlainSelect; |
16 | 18 | import net.sf.jsqlparser.test.TestUtils; |
@@ -50,6 +52,28 @@ public void testGetNotExcapedValue() { |
50 | 52 | assertEquals(expResult, result); |
51 | 53 | } |
52 | 54 |
|
| 55 | + @Test |
| 56 | + public void testGetNotExcapedValueLargeInputIsLinear() { |
| 57 | + // a string literal made of many escaped single quotes used to be unescaped with a |
| 58 | + // deleteCharAt() per pair, which is quadratic and lets a modest literal burn CPU |
| 59 | + int pairs = 1_000_000; |
| 60 | + StringBuilder sb = new StringBuilder(2 * pairs + 2); |
| 61 | + sb.append('\''); |
| 62 | + for (int i = 0; i < pairs; i++) { |
| 63 | + sb.append("''"); |
| 64 | + } |
| 65 | + sb.append('\''); |
| 66 | + StringValue instance = new StringValue(sb.toString()); |
| 67 | + |
| 68 | + String result = assertTimeoutPreemptively(Duration.ofSeconds(2), |
| 69 | + instance::getNotExcapedValue); |
| 70 | + |
| 71 | + assertEquals(pairs, result.length()); |
| 72 | + for (int i = 0; i < result.length(); i++) { |
| 73 | + assertEquals('\'', result.charAt(i)); |
| 74 | + } |
| 75 | + } |
| 76 | + |
53 | 77 | @Test |
54 | 78 | public void testPrefixes() { |
55 | 79 | checkStringValue("E'test'", "test", "E"); |
|
0 commit comments