Make WordPress Core


Ignore:
Timestamp:
11/18/2016 07:32:03 PM (8 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-sanitization.php

    r39222 r39296  
    6464        $this->assertEquals( 'a@b.c', rest_sanitize_value_from_schema( 'a@b.c', $schema ) );
    6565        $this->assertEquals( 'invalid', rest_sanitize_value_from_schema( 'invalid', $schema ) );
     66    }
     67
     68    public function test_format_ip() {
     69        $schema = array(
     70            'type'  => 'string',
     71            'format' => 'ip',
     72        );
     73
     74        $this->assertEquals( '127.0.0.1', rest_sanitize_value_from_schema( '127.0.0.1', $schema ) );
     75        $this->assertEquals( 'hello', rest_sanitize_value_from_schema( 'hello', $schema ) );
     76        $this->assertEquals( '2001:DB8:0:0:8:800:200C:417A', rest_sanitize_value_from_schema( '2001:DB8:0:0:8:800:200C:417A', $schema ) );
    6677    }
    6778
Note: See TracChangeset for help on using the changeset viewer.