This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 9b6ea47 Fixed: missing quotes inside characters when parsing
`PROPERTIES`. (#15999)
9b6ea47 is described below
commit 9b6ea47bd8fdbac91c676e2263619ec7258d5720
Author: lanchengx <[email protected]>
AuthorDate: Sat Mar 12 16:54:06 2022 +0800
Fixed: missing quotes inside characters when parsing `PROPERTIES`. (#15999)
---
.../core/common/CommonDistSQLStatementVisitor.java | 4 ++--
.../core/DatabaseDiscoveryDistSQLStatementVisitor.java | 2 +-
.../parser/core/EncryptDistSQLStatementVisitor.java | 2 +-
.../ReadwriteSplittingDistSQLStatementVisitor.java | 2 +-
.../parser/core/ShadowDistSQLStatementVisitor.java | 3 +--
.../parser/core/ScalingSQLStatementVisitor.java | 2 +-
.../parser/core/ShardingDistSQLStatementVisitor.java | 2 +-
.../sql/common/value/identifier/IdentifierValue.java | 18 ++++++++++++++++++
8 files changed, 26 insertions(+), 9 deletions(-)
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
index 27483c7..6febcc9 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
+++
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
@@ -275,7 +275,7 @@ public final class CommonDistSQLStatementVisitor extends
CommonDistSQLStatementB
}
List<PropertyContext> properties = ctx.properties().property();
for (PropertyContext each : properties) {
- result.setProperty(new
IdentifierValue(each.key.getText()).getValue(), new
IdentifierValue(each.value.getText()).getValue());
+
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()),
IdentifierValue.getQuotedContent(each.value.getText()));
}
return result;
}
@@ -463,7 +463,7 @@ public final class CommonDistSQLStatementVisitor extends
CommonDistSQLStatementB
return result;
}
for (AlgorithmPropertyContext each :
algorithmProperties.algorithmProperty()) {
- result.setProperty(new
IdentifierValue(each.key.getText()).getValue(), new
IdentifierValue(each.value.getText()).getValue());
+
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()),
IdentifierValue.getQuotedContent(each.value.getText()));
}
return result;
}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLSt
[...]
index 4686a54..58f1068 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java
@@ -195,7 +195,7 @@ public final class DatabaseDiscoveryDistSQLStatementVisitor
extends DatabaseDisc
private Properties getProperties(final PropertiesContext ctx) {
Properties result = new Properties();
for (PropertyContext each : ctx.property()) {
- result.setProperty(new
IdentifierValue(each.key.getText()).getValue(), new
IdentifierValue(each.value.getText()).getValue());
+
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()),
IdentifierValue.getQuotedContent(each.value.getText()));
}
return result;
}
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
index 3b31b4f..890d2c7 100644
---
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
@@ -109,7 +109,7 @@ public final class EncryptDistSQLStatementVisitor extends
EncryptDistSQLStatemen
return result;
}
for (AlgorithmPropertyContext each :
ctx.algorithmProperties().algorithmProperty()) {
- result.setProperty(new
IdentifierValue(each.key.getText()).getValue(), new
IdentifierValue(each.value.getText()).getValue());
+
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()),
IdentifierValue.getQuotedContent(each.value.getText()));
}
return result;
}
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwrit
[...]
index 9cb10c6..363fda1 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
@@ -155,7 +155,7 @@ public final class
ReadwriteSplittingDistSQLStatementVisitor extends ReadwriteSp
return result;
}
for (AlgorithmPropertyContext each :
ctx.algorithmProperties().algorithmProperty()) {
- result.setProperty(new
IdentifierValue(each.key.getText()).getValue(), new
IdentifierValue(each.value.getText()).getValue());
+
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()),
IdentifierValue.getQuotedContent(each.value.getText()));
}
return result;
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
index 5a29f8f..fc2181d 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
@@ -53,7 +53,6 @@ import
org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.StringLiteralValue;
import java.util.Collection;
import java.util.Collections;
@@ -101,7 +100,7 @@ public final class ShadowDistSQLStatementVisitor extends
ShadowDistSQLStatementB
private Properties getAlgorithmProperties(final AlgorithmPropertiesContext
ctx) {
Properties result = new Properties();
- ctx.algorithmProperty().forEach(each -> result.put(new
IdentifierValue(each.key.getText()).getValue(), new
StringLiteralValue(each.value.getText()).getValue()));
+ ctx.algorithmProperty().forEach(each ->
result.put(IdentifierValue.getQuotedContent(each.key.getText()),
IdentifierValue.getQuotedContent(each.value.getText())));
return result;
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/scaling/distsql/parser/core/ScalingSQLStatementVisitor.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/scaling/distsql/parser/core/ScalingSQLStatementVisitor.java
index b2857f6..29f4e3b 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/scaling/distsql/parser/core/ScalingSQLStatementVisitor.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/scaling/distsql/parser/core/ScalingSQLStatementVisitor.java
@@ -254,7 +254,7 @@ public final class ScalingSQLStatementVisitor extends
ScalingStatementBaseVisito
return result;
}
for (ScalingStatementParser.AlgorithmPropertyContext each :
ctx.algorithmProperties().algorithmProperty()) {
- result.setProperty(new
IdentifierValue(each.key.getText()).getValue(), new
IdentifierValue(each.value.getText()).getValue());
+
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()),
IdentifierValue.getQuotedContent(each.value.getText()));
}
return result;
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
index 2a08765..eabf347 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
@@ -402,7 +402,7 @@ public final class ShardingDistSQLStatementVisitor extends
ShardingDistSQLStatem
return result;
}
for (AlgorithmPropertyContext each :
ctx.algorithmProperties().algorithmProperty()) {
- result.setProperty(new
IdentifierValue(each.key.getText()).getValue(), new
IdentifierValue(each.value.getText()).getValue());
+
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()),
IdentifierValue.getQuotedContent(each.value.getText()));
}
return result;
}
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/value/identifier/IdentifierValue.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/value/identifier/IdentifierValue.java
index ccd16fa..08277fc 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/value/identifier/IdentifierValue.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/value/identifier/IdentifierValue.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sql.parser.sql.common.value.identifier;
+import com.google.common.base.Strings;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
@@ -52,4 +53,21 @@ public final class IdentifierValue implements
ValueASTNode<String> {
public String getValueWithQuoteCharacters() {
return null == value ? "" : quoteCharacter.wrap(value);
}
+
+ /**
+ * Get quoted content.
+ *
+ * @param text text
+ * @return quote content
+ */
+ public static String getQuotedContent(final String text) {
+ if (Strings.isNullOrEmpty(text)) {
+ return text;
+ }
+ QuoteCharacter quoteCharacter = QuoteCharacter.getQuoteCharacter(text);
+ if (quoteCharacter.equals(QuoteCharacter.NONE)) {
+ return text.trim();
+ }
+ return text.substring(1, text.length() - 1);
+ }
}