Ticket #38818: 38818.2.diff
| File 38818.2.diff, 4.5 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/rest-api.php
diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 741e768..c80c065 100644
a b function rest_parse_request_arg( $value, $request, $param ) { 869 869 } 870 870 871 871 /** 872 * Determines if a IPv4address is valid.872 * Determines if an IP address is valid. 873 873 * 874 * Does not handleIPv6 addresses.874 * Handles both IPv4 and IPv6 addresses. 875 875 * 876 876 * @since 4.7.0 877 877 * 878 * @param string $ip v4 IP 32-bitaddress.879 * @return string|false The valid IP v4address, otherwise false.878 * @param string $ip IP address. 879 * @return string|false The valid IP address, otherwise false. 880 880 */ 881 function rest_is_ip_address( $ipv4 ) { 882 $pattern = '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/'; 883 884 if ( ! preg_match( $pattern, $ipv4 ) ) { 885 return false; 886 } 887 888 return $ipv4; 881 function rest_is_ip_address( $ip ) { 882 return filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) || filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ); 889 883 } 890 884 891 885 /** … … function rest_validate_value_from_schema( $value, $args, $param = '' ) { 1053 1047 return new WP_Error( 'rest_invalid_email', __( 'Invalid email address.' ) ); 1054 1048 } 1055 1049 break; 1056 case 'ip v4' :1050 case 'ip' : 1057 1051 if ( ! rest_is_ip_address( $value ) ) { 1058 /* translators: %s: IP address */ 1052 /* translators: %s: IP address */ 1059 1053 return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not a valid IP address.' ), $value ) ); 1060 1054 } 1061 1055 break; -
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index ccd172f..695dc6e 100644
a b class WP_REST_Comments_Controller extends WP_REST_Controller { 1120 1120 'author_ip' => array( 1121 1121 'description' => __( 'IP address for the object author.' ), 1122 1122 'type' => 'string', 1123 'format' => 'ip v4',1123 'format' => 'ip', 1124 1124 'context' => array( 'edit' ), 1125 1125 'default' => '127.0.0.1', 1126 1126 ), -
tests/phpunit/tests/rest-api/rest-schema-validation.php
diff --git a/tests/phpunit/tests/rest-api/rest-schema-validation.php b/tests/phpunit/tests/rest-api/rest-schema-validation.php index 4e4a111..f504cb7 100644
a b class WP_Test_REST_Schema_Validation extends WP_UnitTestCase { 83 83 $this->assertWPError( rest_validate_value_from_schema( '2016-06-30', $schema ) ); 84 84 } 85 85 86 public function test_format_ip v4() {86 public function test_format_ip() { 87 87 $schema = array( 88 88 'type' => 'string', 89 'format' => 'ip v4',89 'format' => 'ip', 90 90 ); 91 92 // IPv4. 91 93 $this->assertTrue( rest_validate_value_from_schema( '127.0.0.1', $schema ) ); 92 94 $this->assertWPError( rest_validate_value_from_schema( '3333.3333.3333.3333', $schema ) ); 93 95 $this->assertWPError( rest_validate_value_from_schema( '1', $schema ) ); 96 97 // IPv6. 98 $this->assertTrue( rest_validate_value_from_schema( '::1', $schema ) ); // Loopback, compressed, non-routable. 99 $this->assertTrue( rest_validate_value_from_schema( '::', $schema ) ); // Unspecified, compressed, non-routable. 100 $this->assertTrue( rest_validate_value_from_schema( '0:0:0:0:0:0:0:1', $schema ) ); // Loopback, full. 101 $this->assertTrue( rest_validate_value_from_schema( '0:0:0:0:0:0:0:0', $schema ) ); // Unspecified, full. 102 $this->assertTrue( rest_validate_value_from_schema( '2001:DB8:0:0:8:800:200C:417A', $schema ) ); // Unicast, full. 103 $this->assertTrue( rest_validate_value_from_schema( 'FF01:0:0:0:0:0:0:101', $schema ) ); // Multicast, full. 104 $this->assertTrue( rest_validate_value_from_schema( '2001:DB8::8:800:200C:417A', $schema ) ); // Unicast, compressed. 105 $this->assertTrue( rest_validate_value_from_schema( 'FF01::101', $schema ) ); // Multicast, compressed. 106 $this->assertTrue( rest_validate_value_from_schema( 'fe80::217:f2ff:fe07:ed62', $schema ) ); 107 $this->assertWPError( rest_validate_value_from_schema( '', $schema ) ); // Empty string. 108 $this->assertWPError( rest_validate_value_from_schema( '2001:DB8:0:0:8:800:200C:417A:221', $schema ) ); // Unicast, full. 109 $this->assertWPError( rest_validate_value_from_schema( 'FF01::101::2', $schema ) ); // Multicast, compressed. 94 110 } 95 111 96 112 public function test_type_array() {
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)