frankgh commented on code in PR #78: URL: https://github.com/apache/cassandra-sidecar/pull/78#discussion_r1408443127
########## common/src/main/java/org/apache/cassandra/sidecar/common/data/Name.java: ########## @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.sidecar.common.data; + +import java.util.Objects; + +import com.datastax.driver.core.Metadata; + +/** + * Represents the name of keyspaces and tables defined by the grammar in + * <a href="https://cassandra.apache.org/doc/4.1/cassandra/cql/ddl.html#common-definitions">Cassandra CQL common + * definitions</a> + */ +public class Name +{ + private final String unquotedName; + private final String maybeQuotedName; + + /** + * Constructs a {@link Name} object with the provided {@code name}. + * + * @param name the name + */ + Name(String name) + { + this(name, false); + } + + /** + * Constructs a {@link Name} object with the provided {@code unquotedName}, and + * {@code isQuotedFromSource} parameters. For example, if the user-provided input was + * {@code "\"QuotedName\""}, then the parameters for this constructor should be initialized with + * {@code new Name("QuotedTableName", true)}. + * + * @param unquotedName the unquoted name for the table + * @param isQuotedFromSource whether the name was quoted from source + */ + Name(String unquotedName, boolean isQuotedFromSource) Review Comment: we no longer have this constructor, so it's no longer relevant ########## src/main/java/org/apache/cassandra/sidecar/utils/CassandraInputValidator.java: ########## @@ -65,13 +67,16 @@ public CassandraInputValidator() * @throws HttpException when the {@code keyspace} contains invalid characters in the name or when the * keyspace is forbidden */ - public String validateKeyspaceName(@NotNull String keyspace) + public Keyspace validateKeyspaceName(@NotNull String keyspace) { Objects.requireNonNull(keyspace, "keyspace must not be null"); - validatePattern(keyspace, "keyspace"); - if (validationConfiguration.forbiddenKeyspaces().contains(keyspace)) + String unquoted = removeQuotesIfNecessary(keyspace); + // whether the input is quoted from the source + boolean isQuoted = !unquoted.equals(keyspace); + validatePattern(unquoted, keyspace, "keyspace", isQuoted); + if (validationConfiguration.forbiddenKeyspaces().contains(unquoted)) throw new HttpException(HttpResponseStatus.FORBIDDEN.code(), "Forbidden keyspace: " + keyspace); - return keyspace; + return new Keyspace(unquoted, isQuoted); Review Comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

