Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown: Avoid usage of create_function #8868

Merged
merged 2 commits into from
Feb 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions _inc/lib/markdown/extra.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ function Markdown($text) {
return $parser->transform($text);
}

/**
* Returns the length of $text loosely counting the number of UTF-8 characters with regular expression.
* Used by the Markdown_Parser class when mb_strlen is not available.
*
* @since 5.9
*
* @return string Length of the multibyte string
*
*/
function jetpack_utf8_strlen( $text ) {
return preg_match_all( "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", $text, $m );
}

#
# Markdown Parser Class
#
Expand Down Expand Up @@ -1518,14 +1531,14 @@ function _detab_callback($matches) {
function _initDetab() {
#
# Check for the availability of the function in the `utf8_strlen` property
# (initially `mb_strlen`). If the function is not available, create a
# function that will loosely count the number of UTF-8 characters with a
# (initially `mb_strlen`). If the function is not available, use jetpack_utf8_strlen
# that will loosely count the number of UTF-8 characters with a
# regular expression.
#
if (function_exists($this->utf8_strlen)) return;
$this->utf8_strlen = create_function('$text', 'return preg_match_all(
"/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/",
$text, $m);');
if ( function_exists( $this->utf8_strlen ) ) {
return;
}
$this->utf8_strlen = 'jetpack_utf8_strlen';
}


Expand Down