Skip to content

Commit 619f8da

Browse files
feat: normalised backtick quotes
Signed-off-by: Andreas Reichel <[email protected]>
1 parent 157988d commit 619f8da

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/main/java/net/sf/jsqlparser/schema/MultiPartName.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
*/
1010
package net.sf.jsqlparser.schema;
1111

12+
import java.util.regex.Matcher;
1213
import java.util.regex.Pattern;
1314

1415
public interface MultiPartName {
1516
Pattern LEADING_TRAILING_QUOTES_PATTERN = Pattern.compile("^[\"\\[`]+|[\"\\]`]+$");
17+
Pattern BACKTICK_PATTERN = Pattern.compile("`([^`]*)`");
1618

1719
/**
1820
* Removes leading and trailing quotes from a SQL quoted identifier
@@ -33,4 +35,23 @@ static boolean isQuoted(String identifier) {
3335
String getFullyQualifiedName();
3436

3537
String getUnquotedName();
38+
39+
static String replaceBackticksWithDoubleQuotes(String input) {
40+
if (input == null || input.isEmpty()) {
41+
return input;
42+
}
43+
44+
Matcher matcher = BACKTICK_PATTERN.matcher(input);
45+
StringBuilder sb = new StringBuilder();
46+
47+
while (matcher.find()) {
48+
// Replace each backtick-quoted part with double-quoted equivalent
49+
String content = matcher.group(1);
50+
matcher.appendReplacement(sb, "\"" + Matcher.quoteReplacement(content) + "\"");
51+
}
52+
matcher.appendTail(sb);
53+
54+
return sb.toString();
55+
}
56+
3657
}

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ options {
1515
DEBUG_LOOKAHEAD = false;
1616
DEBUG_TOKEN_MANAGER = false;
1717
CACHE_TOKENS = false;
18+
SINGLE_TREE_FILE = false;
1819
// FORCE_LA_CHECK = true;
1920
UNICODE_INPUT = true;
2021
JAVA_TEMPLATE_TYPE = "modern";

0 commit comments

Comments
 (0)