jamesfredley commented on code in PR #16631: URL: https://github.com/apache/grails-core/pull/16631#discussion_r4365978367
########## grails-datamapping-core/src/main/groovy/org/apache/grails/data/core/querytail/H2SqlSyntax.groovy: ########## @@ -0,0 +1,102 @@ +/* + * 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.apache.grails.data.core.querytail + +import groovy.transform.CompileStatic +import groovy.transform.PackageScope + +/** + * 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. A bracket after whitespace, or + * after a comment, is a name in the SQL Server mode but opens an array literal after the + * {@code ARRAY} keyword, which may stand any distance before it, so a statement with one is read + * both ways: a name, which is recorded as written, agrees with itself, while an array literal, + * whose elements are values, does not and withholds the statement. + */ +@CompileStatic +@PackageScope +final class H2SqlSyntax extends StandardSqlSyntax { + + private final boolean bracketAfterWhitespaceIsName + + H2SqlSyntax() { + this(true) + } + + private H2SqlSyntax(boolean bracketAfterWhitespaceIsName) { + super('H2') + this.bracketAfterWhitespaceIsName = bracketAfterWhitespaceIsName + } + + @Override + List<QueryTailSyntax> readings(String sql) { + if (!hasBracketAfterWhitespace(sql)) { + return List.<QueryTailSyntax>of(this) + } + List.<QueryTailSyntax>of(new H2SqlSyntax(true), new H2SqlSyntax(false)) + } + + @Override + int endOfComment(String sql, int index) { + sql.startsWith('//', index) ? endOfLine(sql, index) : super.endOfComment(sql, index) + } + + @Override + int endOfValue(String sql, int index) { + int end = endOfDollarQuoted(sql, index, false) + end != NONE ? end : super.endOfValue(sql, index) + } + + @Override + int endOfQuotedName(String sql, int index) { + char c = sql.charAt(index) + if (c == '`') { + return endOfQuoted(sql, index, '`' as char, false, true) + } + if (c == '[' && !subscript(sql, index) && (bracketAfterWhitespaceIsName || !afterWhitespace(sql, index))) { + return endOfQuoted(sql, index, ']' as char, false, false) + } + super.endOfQuotedName(sql, index) + } + + @Override + protected boolean nestedComments() { + true + } + + private boolean subscript(String sql, int index) { + char previous = previous(sql, index) + isNamePart(previous) || previous == ')' || previous == ']' + } + + private static boolean afterWhitespace(String sql, int index) { + index > 0 && Character.isWhitespace(sql.charAt(index - 1)) + } + + private static boolean hasBracketAfterWhitespace(String sql) { Review Comment: This checks only the character before `[`. `select ARRAY/**/['example-secret']` has `/` there, so the span is copied as an identifier and the secret reaches the file. The new regression has whitespace after `*/`, so it misses this. Treat a comment immediately before `[` as ambiguous, or withhold the statement. Please cover `ARRAY/**/['example-secret']` and `ARRAY /* c */['example-secret']` through the capture API. ########## build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/CompilePlugin.groovy: ########## @@ -181,7 +181,9 @@ class CompilePlugin implements Plugin<Project> { it.options.fork = true // always set an isolated build to ensure grails.factories aren't accidentally merged since every project // in this mono repo should be an isolated projected - it.options.forkOptions.jvmArgs = ['-Xms128M', '-Xmx2G', '-Dgrails.isolated.build=true'] + it.options.forkOptions.jvmArgs = ['-Xms128M', '-Xmx2G', '-Dgrails.isolated.build=true', Review Comment: This commit is marked to be dropped, and it must be. Every Groovy compiler fork now heap-dumps to a fixed `/tmp/querytail-heap` path and runs `jcmd` on OOM. The workflow uploads those dumps on failure. That is shared build behavior, not a switch. Remove this commit before merge. -- 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]
