Elffuss BraidHub

kikocis/java-driver public

Merge pull request #279 from datastax/java655

JAVA-655 Quote single quotes contained in table comments in asCQLQuery method.
Changeseta0bc0c0ae9182d51eacb0256e312c6c0dc5d8ec5ea55bc23d86b42bfc6c15eb2
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2015-03-06 17:55 -08:00
CommitterOlivier Michallat <olim7t@users.noreply.github.com> · 2015-03-06 17:55 -08:00
Parentsc24f41b39166, b3c17058c9fd

Browse the files at this changeset

3 files changed

modified driver-core/CHANGELOG.rst +2 −0
@@ -14,6 +14,8 @@
1414 - [improvement] Use List<?> instead of List<Object> in QueryBuilder API
1515 (JAVA-631)
1616 - [improvement] Exclude Netty POM from META-INF in shaded JAR (JAVA-654)
17+- [bug] Quote single quotes contained in table comments in asCQLQuery method
18+ (JAVA-655)
1719
1820 Merged from 2.0.9_fixes branch:
1921
modified driver-core/src/main/java/com/datastax/driver/core/TableMetadata.java +1 −1
@@ -413,7 +413,7 @@
413413 and(sb, formatted).append("bloom_filter_fp_chance = ").append(options.bfFpChance);
414414 and(sb, formatted).append("caching = '").append(options.caching).append('\'');
415415 if (options.comment != null)
416- and(sb, formatted).append("comment = '").append(options.comment).append('\'');
416+ and(sb, formatted).append("comment = '").append(options.comment.replace("'","''")).append('\'');
417417 and(sb, formatted).append("compaction = ").append(formatOptionMap(options.compaction));
418418 and(sb, formatted).append("compression = ").append(formatOptionMap(options.compression));
419419 if (cassandraVersion.getMajor() >= 2) {
added driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java +25 −0
@@ -0,0 +1,25 @@
1+package com.datastax.driver.core;
2+
3+import java.util.Collection;
4+
5+import com.google.common.collect.Lists;
6+import org.testng.annotations.Test;
7+
8+import static org.assertj.core.api.Assertions.assertThat;
9+
10+public class TableMetadataTest extends CCMBridge.PerClassSingleNodeCluster {
11+ @Override
12+ protected Collection<String> getTableDefinitions() {
13+ return Lists.newArrayList(
14+ "CREATE TABLE single_quote (\n"
15+ + " c1 int PRIMARY KEY\n"
16+ + ") WITH comment = 'comment with single quote '' should work'"
17+ );
18+ }
19+
20+ @Test(groups = "short")
21+ public void should_escape_single_quote_table_comment() {
22+ TableMetadata table = cluster.getMetadata().getKeyspace("ks").getTable("single_quote");
23+ assertThat(table.asCQLQuery()).contains("comment with single quote '' should work");
24+ }
25+}
No newline at the end of the file