Improve regular expressions by using a backreference to match right quote of quote pair when matching attributes.

props kovshenin. see #24225.

git-svn-id: http://core.svn.wordpress.org/trunk@24241 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mark Jaquith 2013-05-10 22:54:33 +00:00
parent 34455bbbd8
commit 74c6071b9d
3 changed files with 10 additions and 10 deletions

View File

@ -3206,7 +3206,7 @@ function links_add_target( $content, $target = '_blank', $tags = array('a') ) {
function _links_add_target( $m ) {
global $_links_add_target;
$tag = $m[1];
$link = preg_replace('|(target=[\'"](.*?)[\'"])|i', '', $m[2]);
$link = preg_replace('|(target=([\'"])(.*?)\2)|i', '', $m[2]);
return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">';
}

View File

@ -1929,11 +1929,11 @@ function get_content_media( $type, &$content, $html = true, $remove = false, $li
$data = array();
foreach ( $items as $item ) {
preg_match_all( '#src=[\'"](.+?)[\'"]#is', $item, $src, PREG_SET_ORDER );
preg_match_all( '#src=([\'"])(.+?)\1#is', $item, $src, PREG_SET_ORDER );
if ( ! empty( $src ) ) {
$srcs = array();
foreach ( $src as $s )
$srcs[] = $s[1];
$srcs[] = $s[2];
$data[] = array_values( array_unique( $srcs ) );
}
@ -2254,9 +2254,9 @@ function get_content_images( &$content, $html = true, $remove = false, $limit =
$srcs = array();
foreach ( $tags as $tag ) {
preg_match( '#src=[\'"](.+?)[\'"]#is', $tag, $src );
if ( ! empty( $src[1] ) ) {
$srcs[] = $src[1];
preg_match( '#src=([\'"])(.+?)\1#is', $tag, $src );
if ( ! empty( $src[2] ) ) {
$srcs[] = $src[2];
if ( $limit > 0 && count( $srcs ) >= $limit )
break;
}
@ -2310,10 +2310,10 @@ function get_content_galleries( &$content, $html = true, $remove = false, $limit
if ( $html ) {
$galleries[] = $gallery;
} else {
preg_match_all( '#src=[\'"](.+?)[\'"]#is', $gallery, $src, PREG_SET_ORDER );
preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER );
if ( ! empty( $src ) ) {
foreach ( $src as $s )
$srcs[] = $s[1];
$srcs[] = $s[2];
}
$data['src'] = array_values( array_unique( $srcs ) );

View File

@ -791,8 +791,8 @@ function get_content_url( &$content, $remove = false ) {
return $trimmed;
// the content is HTML so we grab the first href
} elseif ( preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', $content, $matches ) ) {
return esc_url_raw( $matches[1] );
} elseif ( preg_match( '/<a\s[^>]*?href=([\'"])(.+?)\1/is', $content, $matches ) ) {
return esc_url_raw( $matches[2] );
}
$lines = explode( "\n", $trimmed );