[wp-trac] [WordPress Trac] #51011: Empty string comparison on home option during DB upgrades is invalid
WordPress Trac
noreply at wordpress.org
Fri Aug 14 23:29:39 UTC 2020
#51011: Empty string comparison on home option during DB upgrades is invalid
-----------------------------+-----------------------------
Reporter: fjarrett | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Upgrade/Install | Version: 5.5
Severity: minor | Keywords:
Focuses: |
-----------------------------+-----------------------------
The private `__get_option()` function used during database upgrades was
recently changed in WordPress 5.5 to use a strict comparison operator to
check whether the `home` option value is empty string. However,
`wpdb::get_var` returns `NULL` if the option is empty, so this condition
never actually exists.
https://github.com/WordPress/WordPress/blob/537fd931bc02e6e934a2d774422b897871aa87ad
/wp-admin/includes/upgrade.php#L2570
This was discovered because of an oddity that manifested when using WP-CLI
to run database upgrades on sites that has an empty `home` option, and it
was only reproducible with WordPress 5.5. Full discussion can be found in
the #cli Slack.
https://wordpress.slack.com/archives/C02RP4T41/p1597352867393200
Some possible solutions are:
1. Correct the strict comparison to use `null === $option`
2. Use a more generous empty comparison like `! $option`
3. Refactor `__get_option()` to use `wpdb::get_col` like its
`get_option()` cousin
---
The WP-CLI oddity is fairly easy to reproduce:
1. Empty the `home` option value in the WordPress database:
{{{
$ wp db query "UPDATE wp_options SET option_value = '' WHERE option_name =
'home';"
}}}
''Note: `wp option update home ''` won't work because the core fallback
to `siteurl` prevents it.''
2. Set the `db_version` option to anything less than 48748:
{{{
$ wp option update db_version 47018
Success: Updated 'db_version' option.
}}}
3. Execute the database update:
{{{
$ wp core update-db
Success: WordPress database upgraded successfully from db version 47018 to
48748.
}}}
4. Check the option value:
{{{
$ wp option get home
http://http://example.com
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51011>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list