Skip to content
Open
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/schema/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public final class Server implements MultiPartName {

public static final Pattern SERVER_PATTERN =
Pattern.compile("\\[([^\\]]+?)(?:\\\\([^\\]]+))?\\]");
Pattern.compile("\\[([^\\]\\\\]+)(?:\\\\([^\\]]+))?\\]");

private String serverName;

Expand Down
17 changes: 17 additions & 0 deletions src/test/java/net/sf/jsqlparser/schema/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,27 @@
package net.sf.jsqlparser.schema;

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

import java.time.Duration;
import org.junit.jupiter.api.Test;

public class ServerTest {

@Test
public void testCraftedServerNameDoesNotBacktrack() throws Exception {
final StringBuilder sb = new StringBuilder("[");
for (int i = 0; i < 40000; i++) {
sb.append("a\\");
}
final String crafted = sb.toString();

// an unterminated bracketed name full of backslashes used to backtrack quadratically
final Server server = assertTimeoutPreemptively(Duration.ofSeconds(2),
() -> new Server(crafted));
assertEquals(crafted, server.getFullyQualifiedName());
}

@Test
public void testServerNameParsing() throws Exception {
final String serverName = "LOCALHOST";
Expand Down
Loading