Make WordPress Core


Ignore:
Timestamp:
11/18/2016 07:32:03 PM (7 years ago)
Author:
joehoyle
Message:

REST API: Change “ipv4” types to “ip” to support ipv6.

Stop presuming IP address are IPv4, instead make the type “ip” to be agnostic of IP version. This fixes requests with ipv6 addresses for comments in core.

Props dd32, schlessera, danielbachhuber.
Fixes #38818.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php

    r39222 r39296  
    8484    }
    8585
    86     public function test_format_ipv4() {
     86    public function test_format_ip() {
    8787        $schema = array(
    8888            'type'  => 'string',
    89             'format' => 'ipv4',
     89            'format' => 'ip',
    9090        );
     91
     92        // IPv4.
    9193        $this->assertTrue( rest_validate_value_from_schema( '127.0.0.1', $schema ) );
    9294        $this->assertWPError( rest_validate_value_from_schema( '3333.3333.3333.3333', $schema ) );
    9395        $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.
    94110    }
    95111
Note: See TracChangeset for help on using the changeset viewer.