Skip to content

Commit 6b56718

Browse files
committed
Adding some additional checks for collation name.
1 parent 6f3380c commit 6b56718

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/ServiceManagement/Sql/Commands.SqlDatabase/Services/Server/TSqlConnectionContext.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,12 @@ public Database CreateNewDatabase(
381381
}
382382
}
383383

384+
SqlCollationCheck(databaseCollation);
385+
384386
commandText = string.Format(
385387
commandText,
386388
SqlEscape(databaseName),
387-
SqlEscape(databaseCollation),
389+
databaseCollation,
388390
SqlEscape(maxSizeVal),
389391
SqlEscape(databaseEdition.ToString()),
390392
SqlEscape(serviceObjectiveName));
@@ -405,6 +407,23 @@ public Database CreateNewDatabase(
405407
return GetDatabase(databaseName);
406408
}
407409

410+
private void SqlCollationCheck(string databaseCollation)
411+
{
412+
bool isValid = databaseCollation.All( (c) =>
413+
{
414+
if(!char.IsLetterOrDigit(c) && c != '_')
415+
{
416+
return false;
417+
}
418+
return true;
419+
});
420+
421+
if(!isValid)
422+
{
423+
throw new ArgumentException("Invalid Collation", "Collation");
424+
}
425+
}
426+
408427
/// <summary>
409428
/// Updates the property on the database with the name <paramref name="databaseName"/>.
410429
/// </summary>

0 commit comments

Comments
 (0)