Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jsqlparser/expression/OracleHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class OracleHint extends ASTNodeAccessImpl implements Expression {

private static final Pattern SINGLE_LINE = Pattern.compile("--\\+ *([^ ].*[^ ])");
private static final Pattern MULTI_LINE =
Pattern.compile("/\\*\\+ *([^ ].*[^ ]) *\\*+/", Pattern.MULTILINE | Pattern.DOTALL);
Pattern.compile("\\A/\\*\\+ *([^ ].*[^ ]) *\\*+/", Pattern.MULTILINE | Pattern.DOTALL);

private String value;
private boolean singleLine = false;
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/net/sf/jsqlparser/expression/OracleHintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
*/
package net.sf.jsqlparser.expression;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;

import java.time.Duration;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.test.TestUtils;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -46,4 +50,18 @@ void testMerge() throws JSQLParserException {
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlString, true);
}

@Test
void testCraftedHintCommentDoesNotBacktrack() {
final StringBuilder sb = new StringBuilder("-- /*+ ");
for (int i = 0; i < 100000; i++) {
sb.append('*');
}
final String crafted = sb.toString();

// a line comment carrying an unterminated /*+ marker (no closing */) used to make the
// block hint pattern backtrack quadratically, and it is not an oracle hint anyway
assertTimeoutPreemptively(Duration.ofSeconds(2),
() -> assertFalse(OracleHint.isHintMatch(crafted)));
}

}
Loading