Make WordPress Core


Ignore:
Timestamp:
12/14/2024 11:51:09 PM (16 months ago)
Author:
SergeyBiryukov
Message:

Formatting: Check the result of preg_split() in convert_smilies().

This aims to avoid a fatal error from count() when preg_split() fails on large input.

Includes:

  • Optimizing the regular expression used to split the input by tags to avoid unlimited backtracking for better performance.
  • Adjusting the function logic for better readability.

Follow-up to [340], [4380], [26191].

Props podpirate, nathkrill, rajinsharwar, dmsnell, bjorsch, q0rban, audrasjb, rupw, Ov3rfly, jorbin, nhrrob, chaion07, mcqueen22, azaozz, narenin, roybellingan, SergeyBiryukov.
See #51019.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/convertSmilies.php

    r57987 r59515  
    394394        return $wpsmiliestrans;
    395395    }
     396
     397
     398    /**
     399     * Tests that the function does not throw a fatal error from count()
     400     * when preg_split() fails on large input.
     401     *
     402     * @ticket 51019
     403     */
     404    public function test_smilies_with_large_text_input() {
     405        $text = '<p><img alt="" src="data:image/png;base64,' . str_repeat( 'iVBORw0KGgoAAAAN', 65536 ) . '="></p> :)';
     406        $this->assertStringContainsString( "\xf0\x9f\x99\x82", convert_smilies( $text ) );
     407    }
    396408}
Note: See TracChangeset for help on using the changeset viewer.