Skip to content

Commit

Permalink
fix: double slop (DataLinkDC#3063)
Browse files Browse the repository at this point in the history
Signed-off-by: Lichao <lecho.sun@gmail.com>
Co-authored-by: leechor <leechor@users.noreply.github.com>
  • Loading branch information
leechor and leechor authored Jan 25, 2024
1 parent 65b7194 commit ed1e695
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion dinky-admin/src/test/java/org/dinky/utils/SqlUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ public void testRemoveNote() {

String removedNoteSql = SqlUtil.removeNote(testSql);
Assertions.assertThat(removedNoteSql).isNotNull();
Assertions.assertThat(removedNoteSql).isNotEqualTo(testSql);
Assertions.assertThat(removedNoteSql)
.isEqualTo("//test2\n" + "\n"
+ "\n"
+ "select 1 \n"
+ " from test # test9\n"
+ " where '1' <> '-- ::.' //test6\n"
+ " and 1=1 \n"
+ " and 'zz' <> null;");
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion dinky-common/src/main/java/org/dinky/utils/SqlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static String removeNote(String sql) {
// Remove the special-space characters
sql = sql.replaceAll("\u00A0", " ").replaceAll("[\r\n]+", "\n");
// Remove annotations Support '--aa' , '/**aaa*/' , '//aa' , '#aaa'
Pattern p = Pattern.compile("(?ms)('(?:''|[^'])*')|--.*?$|//.*?$|/\\*[^+].*?\\*/|#.*?$|");
Pattern p = Pattern.compile("(?ms)('(?:''|[^'])*')|--.*?$|/\\*[^+].*?\\*/|");
String presult = p.matcher(sql).replaceAll("$1");
return presult.trim();
}
Expand Down

0 comments on commit ed1e695

Please sign in to comment.