#42195 closed defect (bug) (fixed)
wp_slash() is lossy
Reported by: | johnbillion | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Formatting | Keywords: | dev-feedback has-unit-tests has-patch needs-testing has-dev-note |
Focuses: | Cc: |
Description
Calling wp_slash()
converts all values to strings, causing data loss for integers, floats, and booleans.
Example:
wp_slash( 123 ); // '123' wp_slash( 123.4 ); // '123.4'
The above results in the values being cast to strings.
Booleans are cast to strings too, with a value of '1' or an empty string:
wp_slash( true ); // '1' wp_slash( false ); // ''
This causes particular problems for delete_metadata()
when passing a meta value, because the meta value is slashed before being serialized in order to perform the SQL lookup for matching rows, causing the lookup to fail.
Attachments (3)
Change History (15)
#3
@
7 years ago
Anyone any feedback on the question I pose here: https://core.trac.wordpress.org/ticket/24106#comment:12 ?
#4
@
6 years ago
I think that it can be corrected below, but is there something wrong?
function wp_slash( $value ) { if ( is_array( $value ) ) { foreach ( $value as $k => $v ) { if ( is_array( $v ) ) { $value[ $k ] = wp_slash( $v ); } else { if (is_bool( $v )) { $v = (int) $v; } $value[ $k ] = addslashes( $v ); } } } else { if ( is_bool( $value ) ) { $value = (int) $value; } $value = addslashes( $value ); } return $value; }
#5
@
4 years ago
- Milestone changed from Awaiting Review to 5.5
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
Related: #48605
This ticket was mentioned in PR #288 on WordPress/wordpress-develop by donmhico.
4 years ago
#6
Leave non-string values untouched in wp_slash()
Trac ticket: https://core.trac.wordpress.org/ticket/42195
#7
@
4 years ago
- Keywords has-patch needs-testing added; needs-patch removed
In PR-288, only string values are passed to addslashes()
. Basically non-string values passed to wp_slash()
are just returned.
#8
@
4 years ago
I agree with @jrf that we can simplify this a bit using a map function. Adding a patch that could combine the efforts here and #24106.
#12
@
4 years ago
- Keywords has-dev-note added; needs-dev-note removed
Mentionned in Miscellaneous developer changes note: https://make.wordpress.org/core/2020/07/29/miscellaneous-developer-focused-changes-in-wordpress-5-5/
Related: https://core.trac.wordpress.org/ticket/24106#comment:10