Index: src/wp-admin/includes/network.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-admin/includes/network.php	(revision 46276)
+++ src/wp-admin/includes/network.php	(date 1569272036433)
@@ -135,7 +135,11 @@
 
 	$hostname  = get_clean_basedomain();
 	$has_ports = strstr( $hostname, ':' );
-	if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
+
+	/** This filter is documented in wp-includes/ms-settings.php */
+	$allowed_ports = apply_filters( 'allowed_multisite_ports', array( ':80', ':443' ) );
+
+	if ( ( false !== $has_ports && ! in_array( $has_ports, $allowed_ports ) ) ) {
 		echo '<div class="error"><p><strong>' . __( 'ERROR:' ) . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
 		echo '<p>' . sprintf(
 			/* translators: %s: Port number. */
Index: src/wp-includes/ms-settings.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/ms-settings.php	(revision 46276)
+++ src/wp-includes/ms-settings.php	(date 1569272142301)
@@ -55,12 +55,23 @@
 if ( ! isset( $current_site ) || ! isset( $current_blog ) ) {
 
 	$domain = strtolower( stripslashes( $_SERVER['HTTP_HOST'] ) );
-	if ( substr( $domain, -3 ) == ':80' ) {
-		$domain               = substr( $domain, 0, -3 );
-		$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
-	} elseif ( substr( $domain, -4 ) == ':443' ) {
-		$domain               = substr( $domain, 0, -4 );
-		$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
+
+	/**
+	 * Filters allowed HTTP ports in Multisite.
+	 *
+	 * @param array $allowed_ports The allowed ports. Default is [ ':80', ':443' ].
+	 *
+	 * @since 5.3.0
+	 *
+	 */
+	$allowed_ports = apply_filters( 'allowed_multisite_ports', array( ':80', ':443' ) );
+
+	foreach ( $allowed_ports as $allowed_port ) {
+		$str_length = strlen( $allowed_port );
+		if ( substr( $domain, - $str_length ) == $allowed_port ) {
+			$domain               = substr( $domain, 0, - $str_length );
+			$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, - $str_length );
+		}
 	}
 
 	$path = stripslashes( $_SERVER['REQUEST_URI'] );
Index: src/wp-includes/ms-site.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/ms-site.php	(revision 46276)
+++ src/wp-includes/ms-site.php	(date 1569272205085)
@@ -534,6 +534,7 @@
 	// Sanitize domain if passed.
 	if ( array_key_exists( 'domain', $data ) ) {
 		$data['domain'] = trim( $data['domain'] );
+		$data['domain'] = preg_replace( '|:\d+$|', '', $data['domain'] );
 		$data['domain'] = preg_replace( '/\s+/', '', sanitize_user( $data['domain'], true ) );
 		if ( is_subdomain_install() ) {
 			$data['domain'] = str_replace( '@', '', $data['domain'] );
Index: tests/phpunit/tests/multisite/site.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- tests/phpunit/tests/multisite/site.php	(revision 46276)
+++ tests/phpunit/tests/multisite/site.php	(date 1569272361881)
@@ -1385,6 +1385,25 @@
 						'lang_id'  => 1,
 					),
 				),
+				array(
+					array(
+						'domain' => 'example.com:443',
+					),
+					array(
+						'domain' => 'example.com',
+						'path'   => '/',
+					),
+				),
+				array(
+					array(
+						'domain' => 'example.com:80',
+						'path'   => '/foo',
+					),
+					array(
+						'domain' => 'example.com',
+						'path'   => '/foo/',
+					),
+				),
 			);
 		}
 
