Index: src/wp-includes/plugin.php
===================================================================
--- src/wp-includes/plugin.php	(revision 53427)
+++ src/wp-includes/plugin.php	(working copy)
@@ -720,6 +720,7 @@
 	foreach ( $wp_plugin_paths as $dir => $realdir ) {
 		if ( strpos( $file, $realdir ) === 0 ) {
 			$file = $dir . substr( $file, strlen( $realdir ) );
+						break;
 		}
 	}
 
Index: tests/phpunit/tests/functions/pluginBasename.php
===================================================================
--- tests/phpunit/tests/functions/pluginBasename.php	(revision 53427)
+++ tests/phpunit/tests/functions/pluginBasename.php	(working copy)
@@ -62,4 +62,32 @@
 		$basename = plugin_basename( '/Users/me/Dropbox/Development/Repositories/plugin/trunk/plugin.php' );
 		$this->assertSame( 'trunk/plugin.php', $basename );
 	}
+
+	/**
+	 * @ticket 42670
+	 */
+	public function test_return_correct_basename_for_symlinked_plugins_when_wp_plugin_dir_is_a_subdir_of_a_plugin() {
+
+		/**
+		 * A lookup array saved by WordPress for symlinked plugins, used only by `plugin_basename()`.
+		 *
+		 * @var array<string, string> $wp_plugin_paths An array of path:realpath where path is the path of the symlink in the WP_PLUGIN_DIR and realpath is the actual location in the filesystem that the symlink is pointing to.
+		 * @see wp_register_plugin_realpath()
+		 */
+		global $wp_plugin_paths;
+
+		// e.g. `/Users/brianhenry/Sites/plugin-whose-realpath-contains-everything`.
+		// aka project directory
+		$wp_plugin_dir_grandparent_directory = dirname( WP_PLUGIN_DIR, 3 );
+
+		$wp_plugin_paths = array(
+			WP_PLUGIN_DIR . '/plugin-whose-realpath-contains-everything' => $wp_plugin_dir_grandparent_directory,
+			WP_PLUGIN_DIR . '/woocommerce' => $wp_plugin_dir_grandparent_directory . '/wp-content/plugins/woocommerce',
+		);
+
+		$result = plugin_basename( $wp_plugin_dir_grandparent_directory . '/wp-content/plugins/woocommerce/woocommerce.php' );
+
+		// Actual   :'plugin-whose-realpath-contains-everything/wordpress/wp-content/plugins/woocommerce/woocommerce.php'.
+		$this->assertEquals( 'woocommerce/woocommerce.php', $result );
+	}
 }
