jamesfredley commented on code in PR #16631: URL: https://github.com/apache/grails-core/pull/16631#discussion_r4362919822
########## grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/jdbc/sqltail/H2SqlSyntax.java: ########## @@ -0,0 +1,65 @@ +/* + * 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 + * + * https://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.grails.datastore.gorm.jdbc.sqltail; + +/** + * H2: block comments nest, {@code //} starts a line comment, {@code $$} quotes a string without a + * tag, backticks delimit a name in every compatibility mode, and square brackets delimit a name in + * the SQL Server mode, where they are never a subscript, which is what a bracket after a name, a + * closing parenthesis or a closing bracket is in the other modes. + */ +final class H2SqlSyntax extends StandardSqlSyntax { + + H2SqlSyntax() { + super("H2"); + } + + @Override + public int endOfComment(String sql, int index) { + return sql.startsWith("//", index) ? endOfLine(sql, index) : super.endOfComment(sql, index); + } + + @Override + public int endOfValue(String sql, int index) { + int end = endOfDollarQuoted(sql, index, false); + return end != NONE ? end : super.endOfValue(sql, index); + } + + @Override + public int endOfQuotedName(String sql, int index) { + char c = sql.charAt(index); + if (c == '`') { + return endOfQuoted(sql, index, '`', false, true); + } + if (c == '[' && !subscript(sql, index)) { + return endOfQuoted(sql, index, ']', false, false); + } + return super.endOfQuotedName(sql, index); + } + + @Override + protected boolean nestedComments() { + return true; + } + + private boolean subscript(String sql, int index) { Review Comment: A space before `[` is treated as a quoted identifier. `select ARRAY ['example-secret']` is valid H2 and the secret is copied into the capture unchanged. A comment between `ARRAY` and `[` does the same. Do not treat brackets after whitespace as an identifier when they open an array. Or withhold the statement. Please assert that literal does not reach the file. -- 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]
