Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/08/2014 02:14:29 PM (11 years ago)
Author:
boonebgorges
Message:

Better detection for false positives in meta SQL filters.

Our wrappers for WP's _metadata() functions require some filtering of the SQL
string (to change a column name and, in the case of xprofile, to add an
'object_type' clause). Our str_replace() logic is too generous, creating the
possibility of matching quoted text, as when the meta value contains the string
'WHERE'.

This changeset modifies the filters so that quoted content is swapped out with
placeholders before we run our search-and-replace.

See #5919.
Props tometzky for feedback.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/xprofile/functions.php

    r8987 r9073  
    474474    /**
    475475     * @group xprofilemeta
     476     * @group bp_xprofile_update_meta
     477     * @ticket BP5919
     478     */
     479    public function test_bp_xprofile_update_meta_where_sql_filter_keywords_are_in_quoted_value() {
     480        $g = $this->factory->xprofile_group->create();
     481        $value = "SELECT object_id FROM wp_bp_xprofile_groups WHERE \"foo\" VALUES (foo = 'bar'";
     482        bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
     483        bp_xprofile_update_meta( $g, 'group', 'foo', $value );
     484        $this->assertSame( $value, bp_xprofile_get_meta( $g, 'group', 'foo' ) );
     485    }
     486
     487    /**
     488     * @group xprofilemeta
     489     * @group bp_xprofile_update_meta
     490     * @ticket BP5919
     491     */
     492    public function test_bp_xprofile_update_meta_where_meta_id_is_in_quoted_value() {
     493        $g = $this->factory->xprofile_group->create();
     494        $value = "foo meta_id bar";
     495        bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
     496        bp_xprofile_update_meta( $g, 'group', 'foo', $value );
     497        $this->assertSame( $value, bp_xprofile_get_meta( $g, 'group', 'foo' ) );
     498    }
     499
     500    /**
     501     * @group xprofilemeta
    476502     * @group bp_xprofile_add_meta
    477503     */
Note: See TracChangeset for help on using the changeset viewer.