Page MenuHomePhabricator

[postgres] help message says "-" allowed in db name, but regex doesn't allow it
Open, LowPublic

Description

Our installer code only allows "-" in mysql db names. However the help message says its allowed for postgress.

Should double check it works in postgress ( http://stackoverflow.com/questions/10216784/what-is-a-valid-postgresql-database-name suggests it does if it is quoted), and should either change the regex or change the help message.

See also bug 25969


Version: 1.23.0
Severity: minor

Details

Reference
bz60560

Related Objects

View Standalone Graph
This task is connected to more than 200 other tasks. Only direct parents and subtasks are shown here. Use View Standalone Graph to show more of the graph.

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 2:52 AM
bzimport set Reference to bz60560.
bzimport added a subscriber: Unknown Object (MLST).

The hard part of this bug is that someone should actually test that using a db name with a "-" in it actually works with mediawiki.

After changing the regex, I installed against git HEAD with a PostgreSQL database named "my-wiki", and created and edited pages and uploaded files with no problem. Same with "my_wiki-".

I also tried "-my_wiki", but that failed to upload files to it. But I also tried "-my_wiki" against mysql in 1.22.6, and that too failed.

I did not test any extensions. I assumed that all connections where directed through a single codepath, and so if it worked anywhere it would work everywhere. But the failure to upload files to databases with leading hyphens contradicts that. Are there specific extensions I should test?

So my conclusion is that database names with hyphens in them (no matter how unwise they may be) are supported by PostgreSQL just as much as by MySQL.

Just to clarify: The PostgreSQL-specific regular expressions are in includes/installer/PostgresInstaller.php, line 91ff.:

// Validate them
$status = Status::newGood();
if ( !strlen( $newValues['wgDBname'] ) ) {
        $status->fatal( 'config-missing-db-name' );
} elseif ( !preg_match( '/^[a-zA-Z0-9_]+$/', $newValues['wgDBname'] ) ) {
        $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
}
if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) {
        $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] );
}

The messages are defined in includes/installer/i18n/en.json (et al.), line 146ff. as:

        "config-invalid-db-name": "Invalid database name \"$1\".\nUse only ASCII letters (a-z, A-Z), numbers (0-9), underscores (_) and hyphens (-).",
[…]
        "config-invalid-schema": "Invalid schema for MediaWiki \"$1\".\nUse only ASCII letters (a-z, A-Z), numbers (0-9) and underscores (_).",

@Jjanes, could you please upload your change of the regular expressions to Gerrit? Thanks.

Jdforrester-WMF subscribed.

Migrating from the old tracking task to a tag for PostgreSQL-related tasks.