Index: formatting.php
===================================================================
--- formatting.php	(revision 12294)
+++ formatting.php	(working copy)
@@ -173,12 +173,15 @@
  * or 'false'.
  *
  * @since 0.71
+ * @uses $shortcode_tags
  *
  * @param string $pee The text which has to be formatted.
  * @param int|bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
  * @return string Text which has been converted into correct paragraph tags.
  */
 function wpautop($pee, $br = 1) {
+	global $shortcode_tags;
+
 	if ( trim($pee) === '' )
 		return '';
 	$pee = $pee . "\n"; // just to make things a little easier, pad the end
@@ -216,8 +219,12 @@
 	if (strpos($pee, '<pre') !== false)
 		$pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
 	$pee = preg_replace( "|\n</p>$|", '</p>', $pee );
-	$pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone
 
+	// don't auto-p wrap shortcodes that stand alone
+	$tagnames = array_keys($shortcode_tags);
+	$tagregexp = join( '|', array_map('preg_quote', $tagnames) );
+	$pee = preg_replace('/<p>\\s*?(.?\\[('.$tagregexp.')\\b.*?\\/?\\](?:.+?\\[\\/\\2\\])?.?)\\s*<\\/p>/s', '$1', $pee);
+
 	return $pee;
 }
 
Index: shortcodes.php
===================================================================
--- shortcodes.php	(revision 12294)
+++ shortcodes.php	(working copy)
@@ -176,7 +176,7 @@
 	$tagregexp = join( '|', array_map('preg_quote', $tagnames) );
 
 	// WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes()
-	return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
+	return '(.?)\\[('.$tagregexp.')\\b(.*?)\\/?\\](?:(.+?)\\[\\/\\2\\])?(.?)';
 }
 
 /**
@@ -194,19 +194,19 @@
 	global $shortcode_tags;
 
 	// allow [[foo]] syntax for escaping a tag
-	if ($m[1] == '[' && $m[6] == ']') {
+	if ($m[1] == '[' && $m[5] == ']') {
 		return substr($m[0], 1, -1);
 	}
 
 	$tag = $m[2];
 	$attr = shortcode_parse_atts($m[3]);
 
-	if ( isset($m[5]) ) {
+	if ( isset($m[4]) ) {
 		// enclosing tag - extra parameter
-		return $m[1] . call_user_func($shortcode_tags[$tag], $attr, $m[5], $m[2]) . $m[6];
+		return $m[1] . call_user_func($shortcode_tags[$tag], $attr, $m[4], $m[2]) . $m[5];
 	} else {
 		// self-closing tag
-		return $m[1] . call_user_func($shortcode_tags[$tag], $attr, NULL, $m[2]) . $m[6];
+		return $m[1] . call_user_func($shortcode_tags[$tag], $attr, NULL, $m[2]) . $m[5];
 	}
 }
 
@@ -290,9 +290,9 @@
 
 	$pattern = get_shortcode_regex();
 
-	return preg_replace('/'.$pattern.'/s', '$1$6', $content);
+	return preg_replace('/'.$pattern.'/s', '$1$5', $content);
 }
 
 add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()
 
-?>
\ No newline at end of file
+?>
