Skip to content

Commit 8889ecf

Browse files
committed
Support UTF-8 Table names
Added support for UTF-8 Table names (including combined character)
1 parent 5908326 commit 8889ecf

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/PhpSpreadsheet/Worksheet/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ public function setName(string $name)
103103
) {
104104
throw new PhpSpreadsheetException('The table name can\'t be the same as a cell reference');
105105
}
106-
if (!preg_match('/^[A-Z_\\\\]/i', $name)) {
106+
if (!preg_match('/^[\p{L}_\\\\]/iu', $name)) {
107107
throw new PhpSpreadsheetException('The table name must begin a name with a letter, an underscore character (_), or a backslash (\)');
108108
}
109-
if (!preg_match('/^[A-Z_\\\\][A-Z0-9\._]+$/i', $name)) {
109+
if (!preg_match('/^[\p{L}_\\\\][\p{L}\p{M}0-9\._]+$/iu', $name)) {
110110
throw new PhpSpreadsheetException('The table name contains invalid characters');
111111
}
112112

tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public function validTableNamesProvider(): array
4242
['_table_2', '_table_2'],
4343
['\table_3', '\table_3'],
4444
[" Table_4 \n", 'Table_4'],
45+
['table.5', 'table.5'],
46+
['தமிழ்', 'தமிழ்'], // UTF-8 letters with combined character
4547
];
4648
}
4749

@@ -72,6 +74,7 @@ public function invalidTableNamesProvider(): array
7274
['R11C11'],
7375
['123'],
7476
['=Table'],
77+
['ிக'], // starting with UTF-8 combined character
7578
[bin2hex(random_bytes(255))], // random string with length greater than 255
7679
];
7780
}

0 commit comments

Comments
 (0)