[wp-trac] [WordPress Trac] #38818: REST API: Support ipv6 for `author_ip` in comments endpoint

WordPress Trac noreply at wordpress.org
Wed Nov 16 15:09:30 UTC 2016


#38818: REST API: Support ipv6 for `author_ip` in comments endpoint
-------------------------------------------------+-------------------------
 Reporter:  dd32                                 |       Owner:
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  4.7
Component:  Comments                             |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:  rest-api
  testing                                        |
-------------------------------------------------+-------------------------
Changes (by schlessera):

 * keywords:  needs-patch => has-patch has-unit-tests needs-testing


Comment:

 I've created a patch to allow for the comment author IP address to be
 either an IPv4 or an IPv6 address.

 To achieve this while staying compatible to both the code that uses the
 `rest_is_ip_address()` function as well as the code that uses the format
 validation `ipv4`, I've split up `rest_is_ip_address()` in the following
 way:

 `rest_is_ip_address( $ip )` => IPv4 & IPv6
 `rest_is_ipv4_address( $ipv4 )` => IPv4 only
 `rest_is_ipv6_address( $ipv6 )` => IPv6 only

 I've added corresponding unit tests to make sure IPv6 addresses are
 correctly addressed.

 In the same vein, there are now three different validation formats: `ip`,
 `ipv4` and `ipv6`.

 The validation format for a comment's `author_ip` was changed from `ipv4`
 to `ip`.

 Note: As I was not aware of a specific reason why the PHP's built-in
 `filter_var` with the flag `FILTER_VALIDATE_IP` was not used (the IPv4
 check used a custom regex), I've implemented each of these functions as
 such a `filter_var()` call, which should provide the best performance.
 `filter_var` is available in PHP 5.2+.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38818#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list