Index: src/wp-includes/class-wp-widget.php
===================================================================
--- src/wp-includes/class-wp-widget.php	(revision 35864)
+++ src/wp-includes/class-wp-widget.php	(working copy)
@@ -183,10 +183,11 @@
 	 * @param string $field_name Field name
 	 * @return string Name attribute for $field_name
 	 */
-	public function get_field_name($field_name) {
-		if ( false === $pos = strpos( $field_name, '[' ) ) {
+	public function get_field_name( $field_name ) {
+		if ( ! preg_match( '/]$/', $field_name ) ) {
 			return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']';
 		} else {
+			$pos = strpos( $field_name, '[' );
 			return 'widget-' . $this->id_base . '[' . $this->number . '][' . substr_replace( $field_name, '][', $pos, strlen( '[' ) );
 		}
 	}
Index: tests/phpunit/tests/widgets.php
===================================================================
--- tests/phpunit/tests/widgets.php	(revision 35864)
+++ tests/phpunit/tests/widgets.php	(working copy)
@@ -351,6 +351,10 @@
 				'widget-foo[2][posttypes][4][][6]',
 				'posttypes[4][][6]',
 			),
+			array(
+				'widget-foo[2][posttypes][name]',
+				'posttypes][name',
+			),
 		);
 	}
 
