You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Strips leading whitespace, `--`/`/* … */` comments, and opening parens from a
249
+
* statement so the read-only leader keyword can be detected even when a query
250
+
* starts with a comment (e.g. `-- note\nSELECT …`) or wrapping parens.
251
+
*/
252
+
functionstripLeadingNoise(sql: string): string{
253
+
lets=sql.trim()
254
+
for(;;){
255
+
if(s.startsWith('--')){
256
+
constnewline=s.indexOf('\n')
257
+
s=(newline===-1 ? '' : s.slice(newline+1)).trim()
258
+
}elseif(s.startsWith('/*')){
259
+
constclose=s.indexOf('*/')
260
+
s=(close===-1 ? '' : s.slice(close+2)).trim()
261
+
}elseif(s.startsWith('(')){
262
+
s=s.slice(1).trim()
263
+
}else{
264
+
returns
265
+
}
266
+
}
267
+
}
268
+
247
269
exportasyncfunctionexecuteClickHouseQuery(
248
270
config: ClickHouseConnectionConfig,
249
271
query: string,
250
272
options: {enforceReadOnly?: boolean}={}
251
273
): Promise<ClickHouseRowsResult>{
252
274
if(options.enforceReadOnly){
253
-
// Strip leading parens so wrapped selects like "(SELECT ...)" still validate.
254
-
constleader=query.trim().replace(/^\(+\s*/,'')
275
+
// Strip leading comments/parens so wrapped or commented selects still validate.
276
+
constleader=stripLeadingNoise(query)
255
277
if(!READ_ONLY_STATEMENT.test(leader)){
256
278
thrownewError(
257
279
'The query operation only allows read-only statements (SELECT, WITH, SHOW, DESCRIBE, EXPLAIN, EXISTS). Use the Execute Raw SQL operation to run writes or DDL.'
0 commit comments