Commit 4e19a75
committed
product: fix CREATE DATABASE failure on special characters
The PostgreSQL path of _create_database() interpolated the user-supplied
database name directly into a CREATE DATABASE statement via an f-string.
This caused syntax errors for any name that is not a legal unquoted
PostgreSQL identifier - in particular names containing a dash
(e.g. 'test-product') or starting with a digit (e.g. '1team') - both
reported by users via the GUI's product creation dialog.
SQLAlchemy does not auto-quote identifiers in free-form text() clauses,
so the fix has two parts:
* Quote the identifier explicitly using the dialect's
IdentifierPreparer before embedding it in the statement. This
produces a properly double-quoted name such as CREATE DATABASE
"test-product", which PostgreSQL accepts.
* Validate the database name in addProduct() using the new
is_valid_postgresql_db_name() helper, so that inputs containing
quotes, semicolons, whitespace, control characters, or that
exceed PostgreSQL's 63-byte identifier limit are rejected with a
clear error message before any SQL is issued, rather than crashing
later with an opaque driver error.1 parent c92bf27 commit 4e19a75
1 file changed
Lines changed: 18 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
372 | 375 | | |
373 | 376 | | |
374 | 377 | | |
| |||
411 | 414 | | |
412 | 415 | | |
413 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
414 | 430 | | |
415 | 431 | | |
416 | 432 | | |
| |||
0 commit comments