Skip to content

Commit 4324774

Browse files
committed
fix: escape double quotes in SQL identifier quoting
1 parent e734b58 commit 4324774

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/main/java/org/sap/cytoscape/internal/utils/HanaUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static String toStrNull(Object obj){
2121
* @return Quoted String
2222
*/
2323
public static String quoteIdentifier(String id){
24-
return '"' + id + '"';
24+
return '"' + id.replace("\"", "\"\"") + '"';
2525
}
2626

2727
/**

src/test/java/HanaUtilsTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ public void testQuoteIdentifier_emptyString() {
3737
Assert.assertEquals("\"\"", HanaUtils.quoteIdentifier(""));
3838
}
3939

40+
@Test
41+
public void testQuoteIdentifier_containsDoubleQuote() {
42+
// An embedded " must be escaped as "" per SQL standard identifier quoting.
43+
// Without escaping, foo"bar produces "foo"bar" which breaks out of the identifier.
44+
Assert.assertEquals("\"foo\"\"bar\"", HanaUtils.quoteIdentifier("foo\"bar"));
45+
}
46+
4047
// -------------------------------------------------------------------------
4148
// isCloudEdition
4249
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)