Index: src/wp-includes/media.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/media.php	(revision 30831)
+++ src/wp-includes/media.php	(revision )
@@ -875,8 +875,20 @@
 	$caption_width = apply_filters( 'img_caption_shortcode_width', $caption_width, $atts, $content );
 
 	$style = '';
-	if ( $caption_width )
-		$style = 'style="width: ' . (int) $caption_width . 'px" ';
+	if ( $caption_width ) {
+		$margin = '';
+		$caption_width_unit = 'px';
+		if ( '%' == substr( $caption_width, - 1 ) ) {
+			$caption_width      = (int) substr( $caption_width, 0, - 1 );
+			$caption_width_unit = '%';
+			// for widths less than 100% we need to add a right margin of 10 pixels
+			// to prevent post content from running up against a floated image
+			if ( $caption_width < 100 ) {
+				$margin = ' margin-right: 10px;';
+			}
+		}
+		$style = 'style="width: ' . (int) $caption_width . $caption_width_unit . ';' . $margin . '" ';
+	}
 
 	return '<div ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
 	. do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
