File tree 1 file changed +21
-1
lines changed
csharp/src/Drivers/Databricks
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -150,7 +150,14 @@ public async Task ApplyServerSidePropertiesAsync()
150
150
151
151
foreach ( var property in serverSideProperties )
152
152
{
153
- string query = $ "SET { property . Key } ={ property . Value } ";
153
+ if ( ! IsValidPropertyName ( property . Key ) )
154
+ {
155
+ Debug . WriteLine ( $ "Skipping invalid property name: { property . Key } ") ;
156
+ continue ;
157
+ }
158
+
159
+ string escapedValue = EscapeSqlString ( property . Value ) ;
160
+ string query = $ "SET { property . Key } ={ escapedValue } ";
154
161
statement . SqlQuery = query ;
155
162
156
163
try
@@ -164,6 +171,19 @@ public async Task ApplyServerSidePropertiesAsync()
164
171
}
165
172
}
166
173
174
+ private bool IsValidPropertyName ( string propertyName )
175
+ {
176
+ // Allow only alphanumeric characters and underscores in property names
177
+ return System . Text . RegularExpressions . Regex . IsMatch (
178
+ propertyName ,
179
+ @"^[a-zA-Z0-9_]+$" ) ;
180
+ }
181
+
182
+ private string EscapeSqlString ( string value )
183
+ {
184
+ return "`" + value . Replace ( "`" , "``" ) + "`" ;
185
+ }
186
+
167
187
protected override Task < TGetResultSetMetadataResp > GetResultSetMetadataAsync ( TGetSchemasResp response , CancellationToken cancellationToken = default ) =>
168
188
Task . FromResult ( response . DirectResults . ResultSetMetadata ) ;
169
189
protected override Task < TGetResultSetMetadataResp > GetResultSetMetadataAsync ( TGetCatalogsResp response , CancellationToken cancellationToken = default ) =>
You can’t perform that action at this time.
0 commit comments