Skip to content

Commit 2d0d013

Browse files
committed
Validating table names.
1 parent 6466eb8 commit 2d0d013

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

PowerSync/PowerSync.Common/DB/Schema/Schema.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ public class Schema(Dictionary<string, Table> tables)
99

1010
public void Validate()
1111
{
12-
foreach (var table in Tables.Values)
12+
foreach (var kvp in Tables)
1313
{
14+
var tableName = kvp.Key;
15+
var table = kvp.Value;
16+
17+
if (Table.InvalidSQLCharacters.IsMatch(tableName))
18+
{
19+
throw new Exception($"Invalid characters in table name: {tableName}");
20+
}
21+
1422
table.Validate();
1523
}
1624
}

PowerSync/PowerSync.Common/DB/Schema/Table.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class TableOptions(
2020

2121
public class Table
2222
{
23-
private static readonly Regex InvalidSQLCharacters = new Regex(@"[""'%,.#\s\[\]]", RegexOptions.Compiled);
23+
public static readonly Regex InvalidSQLCharacters = new Regex(@"[""'%,.#\s\[\]]", RegexOptions.Compiled);
2424

2525

2626
protected TableOptions Options { get; init; } = null!;

0 commit comments

Comments
 (0)