Skip to content

Commit 5c2abef

Browse files
Copilotswissspidy
andauthored
fix create backslash handling in transformer write path
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 5385a92 commit 5c2abef

1 file changed

Lines changed: 34 additions & 14 deletions

File tree

‎src/Config_Command.php‎

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,32 +348,39 @@ public function create( $_, $assoc_args ) {
348348

349349
$value_map = [
350350
'dbname' => [
351-
'type' => 'constant',
352-
'name' => 'DB_NAME',
351+
'type' => 'constant',
352+
'name' => 'DB_NAME',
353+
'anchor' => '/** Database username */',
353354
],
354355
'dbuser' => [
355-
'type' => 'constant',
356-
'name' => 'DB_USER',
356+
'type' => 'constant',
357+
'name' => 'DB_USER',
358+
'anchor' => '/** Database password */',
357359
],
358360
'dbpass' => [
359-
'type' => 'constant',
360-
'name' => 'DB_PASSWORD',
361+
'type' => 'constant',
362+
'name' => 'DB_PASSWORD',
363+
'anchor' => '/** Database hostname */',
361364
],
362365
'dbhost' => [
363-
'type' => 'constant',
364-
'name' => 'DB_HOST',
366+
'type' => 'constant',
367+
'name' => 'DB_HOST',
368+
'anchor' => '/** Database charset to use in creating database tables. */',
365369
],
366370
'dbcharset' => [
367-
'type' => 'constant',
368-
'name' => 'DB_CHARSET',
371+
'type' => 'constant',
372+
'name' => 'DB_CHARSET',
373+
'anchor' => '/** The database collate type. Don\'t change this if in doubt. */',
369374
],
370375
'dbcollate' => [
371-
'type' => 'constant',
372-
'name' => 'DB_COLLATE',
376+
'type' => 'constant',
377+
'name' => 'DB_COLLATE',
378+
'anchor' => '/**#@+',
373379
],
374380
'dbprefix' => [
375-
'type' => 'variable',
376-
'name' => 'table_prefix',
381+
'type' => 'variable',
382+
'name' => 'table_prefix',
383+
'anchor' => '/* Add any custom values between this line and the "stop editing" line. */',
377384
],
378385
];
379386

@@ -388,6 +395,19 @@ public function create( $_, $assoc_args ) {
388395
$assoc_args[ $arg_name ],
389396
[ 'add' => true ]
390397
);
398+
399+
if ( false !== strpos( $assoc_args[ $arg_name ], '\\' ) ) {
400+
$config_transformer->remove( $entry['type'], $entry['name'] );
401+
$config_transformer->add(
402+
$entry['type'],
403+
$entry['name'],
404+
$assoc_args[ $arg_name ],
405+
[
406+
'anchor' => $entry['anchor'],
407+
'placement' => 'before',
408+
]
409+
);
410+
}
391411
}
392412

393413
if ( ! empty( $assoc_args['keys-and-salts'] ) ) {

0 commit comments

Comments
 (0)