Index: wp-includes/kses.php
===================================================================
--- wp-includes/kses.php	(revision 40333)
+++ wp-includes/kses.php	(working copy)
@@ -913,21 +913,21 @@
  * @param array  $allowed_protocols Allowed protocols to keep
  * @return array List of attributes after parsing
  */
-function wp_kses_hair($attr, $allowed_protocols) {
+function wp_kses_hair( $attr, $allowed_protocols ) {
 	$attrarr = array();
 	$mode = 0;
 	$attrname = '';
-	$uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
+	$uris = array( 'xmlns', 'profile', 'href', 'src', 'srcset', 'sizes', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action' );
 
 	// Loop through the whole attribute list
 
-	while (strlen($attr) != 0) {
+	while ( strlen( $attr ) !== 0 ) {
 		$working = 0; // Was the last operation successful?
 
-		switch ($mode) {
+		switch ( $mode ) {
 			case 0 : // attribute name, href for instance
 
-				if ( preg_match('/^([-a-zA-Z:]+)/', $attr, $match ) ) {
+				if ( preg_match( '/^([-a-zA-Z:]+)/', $attr, $match ) ) {
 					$attrname = $match[1];
 					$working = $mode = 1;
 					$attr = preg_replace( '/^[-a-zA-Z:]+/', '', $attr );
@@ -937,22 +937,20 @@
 
 			case 1 : // equals sign or valueless ("selected")
 
-				if (preg_match('/^\s*=\s*/', $attr)) // equals sign
-					{
+				if ( preg_match( '/^\s*=\s*/', $attr ) ) { // equals sign
 					$working = 1;
 					$mode = 2;
-					$attr = preg_replace('/^\s*=\s*/', '', $attr);
+					$attr = preg_replace( '/^\s*=\s*/', '', $attr );
 					break;
 				}
 
-				if (preg_match('/^\s+/', $attr)) // valueless
-					{
+				if ( preg_match( '/^\s+/', $attr ) ) { // valueless
 					$working = 1;
 					$mode = 0;
-					if(false === array_key_exists($attrname, $attrarr)) {
-						$attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
+					if ( false === array_key_exists( $attrname, $attrarr ) ) {
+						$attrarr[ $attrname ] = array( 'name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y' );
 					}
-					$attr = preg_replace('/^\s+/', '', $attr);
+					$attr = preg_replace( '/^\s+/', '', $attr );
 				}
 
 				break;
@@ -959,68 +957,43 @@
 
 			case 2 : // attribute value, a URL after href= for instance
 
-				if (preg_match('%^"([^"]*)"(\s+|/?$)%', $attr, $match))
-					// "value"
-					{
-					$thisval = $match[1];
-					if ( in_array(strtolower($attrname), $uris) )
-						$thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
+				$scenarios = array(
+					array( '%^"([^"]*)"(\s+|/?$)%', "$attrname=\"$thisval\"", '/^"[^"]*"(\s+|$)/' ), // "value"
+					array( "%^'([^']*)'(\s+|/?$)%", "$attrname='$thisval'", "/^'[^']*'(\s+|$)/" ), // 'value'
+					array( "%^([^\s\"']+)(\s+|/?$)%", "$attrname=\"$thisval\"", "%^[^\s\"']+(\s+|$)%" ), // value
+				);
 
-					if(false === array_key_exists($attrname, $attrarr)) {
-						$attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
-					}
-					$working = 1;
-					$mode = 0;
-					$attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
-					break;
-				}
+				foreach ( $scenarios as $key => $scenario ) {
+					if ( preg_match( $scenario[0], $attr, $match ) ) {
+						$thisval = $match[1];
+						if ( in_array( strtolower( $attrname ), $uris, true ) ) {
+							$thisval = wp_kses_bad_protocol( $thisval, $allowed_protocols );
+						}
 
-				if (preg_match("%^'([^']*)'(\s+|/?$)%", $attr, $match))
-					// 'value'
-					{
-					$thisval = $match[1];
-					if ( in_array(strtolower($attrname), $uris) )
-						$thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
-
-					if(false === array_key_exists($attrname, $attrarr)) {
-						$attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname='$thisval'", 'vless' => 'n');
+						if ( false === array_key_exists( $attrname, $attrarr ) ) {
+							$attrarr[ $attrname ] = array( 'name' => $attrname, 'value' => $thisval, 'whole' => $scenario[1], 'vless' => 'n' );
+						}
+						$working = 1;
+						$mode = 0;
+						$attr = preg_replace( $scenario[2], '', $attr );
+						break;
 					}
-					$working = 1;
-					$mode = 0;
-					$attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
-					break;
 				}
 
-				if (preg_match("%^([^\s\"']+)(\s+|/?$)%", $attr, $match))
-					// value
-					{
-					$thisval = $match[1];
-					if ( in_array(strtolower($attrname), $uris) )
-						$thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
-
-					if(false === array_key_exists($attrname, $attrarr)) {
-						$attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
-					}
-					// We add quotes to conform to W3C's HTML spec.
-					$working = 1;
-					$mode = 0;
-					$attr = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
-				}
-
 				break;
 		} // switch
 
-		if ($working == 0) // not well formed, remove and try again
-		{
-			$attr = wp_kses_html_error($attr);
+		if ( 0 === $working ) { // not well formed, remove and try again
+			$attr = wp_kses_html_error( $attr );
 			$mode = 0;
 		}
 	} // while
 
-	if ($mode == 1 && false === array_key_exists($attrname, $attrarr))
-		// special case, for when the attribute list ends with a valueless
-		// attribute like "selected"
-		$attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
+	// special case, for when the attribute list ends with a valueless
+	// attribute like "selected"
+	if ( 1 === $mode && false === array_key_exists( $attrname, $attrarr ) ) {
+		$attrarr[ $attrname ] = array( 'name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y' );
+	}
 
 	return $attrarr;
 }
