8000 `in_array()` should only ever be used in strict mode. · WP-API/WP-API@6ad437e · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Commit 6ad437e

Browse files
committed
in_array() should only ever be used in strict mode.
1 parent 3ba64b7 commit 6ad437e

7 files changed

+31
-31
lines changed

plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ function rest_validate_request_arg( $value, $request, $param ) {
455455
$args = $attributes['args'][ $param ];
456456

457457
if ( ! empty( $args['enum'] ) ) {
458-
if ( ! in_array( $value, $args['enum'] ) ) {
458+
if ( ! in_array( $value, $args['enum'], true ) ) {
459459
return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: list of valid values */ __( '%1$s is not one of %2$s.' ), $param, implode( ', ', $args['enum'] ) ) );
460460
}
461461
}

tests/test-rest-attachments-controller.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ public function test_get_items() {
169169
$data = $response->get_data();
170170
$this->assertCount( 2, $data );
171171
$ids = wp_list_pluck( $data, 'id' );
172-
$this->assertTrue( in_array( $id1, $ids ) );
173-
$this->assertFalse( in_array( $id2, $ids ) );
174-
$this->assertTrue( in_array( $id3, $ids ) );
172+
$this->assertTrue( in_array( $id1, $ids, true ) );
173+
$this->assertFalse( in_array( $id2, $ids, true ) );
174+
$this->assertTrue( in_array( $id3, $ids, true ) );
175175

176176
$this->check_get_posts_response( $response );
177177
}
@@ -198,9 +198,9 @@ public function test_get_items_logged_in_editor() {
198198
$data = $response->get_data();
199199
$this->assertCount( 3, $data );
200200
$ids = wp_list_pluck( $data, 'id' );
201-
$this->assertTrue( in_array( $id1, $ids ) );
202-
$this->assertTrue( in_array( $id2, $ids ) );
203-
$this->assertTrue( in_array( $id3, $ids ) );
201+
$this->assertTrue( in_array( $id1, $ids, true ) );
202+
$this->assertTrue( in_array( $id2, $ids, true ) );
203+
$this->assertTrue( in_array( $id3, $ids, true ) );
204204
}
205205

206206
public function test_get_items_media_type() {
< 8000 div class="diff-text-inner color-fg-muted">

tests/test-rest-categories-controller.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ public function test_get_items_exclude_query() {
198198
$request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
199199
$response = $this->server->dispatch( $request );
200200
$data = $response->get_data();
201-
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
202-
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
201+
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
202+
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
203203
$request->set_param( 'exclude', array( $id2 ) );
204204
$response = $this->server->dispatch( $request );
205205
$data = $response->get_data();
206-
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
207-
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
206+
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
207+
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
208208
}
209209

210210
public function test_get_items_orderby_args() {

tests/test-rest-comments-controller.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function test_get_items_without_private_post_permission() {
150150
$this->assertEquals( 200, $response->get_status() );
151151

152152
$collection_data = $response->get_data();
153-
$this->assertFalse( in_array( $private_comment, wp_list_pluck( $collection_data, 'id' ) ) );
153+
$this->assertFalse( in_array( $private_comment, wp_list_pluck( $collection_data, 'id' ), true ) );
154154
}
155155

156156
public function test_get_items_with_private_post_permission() {
@@ -168,7 +168,7 @@ public function test_get_items_with_private_post_permission() {
168168
$this->assertEquals( 200, $response->get_status() );
169169

170170
$collection_data = $response->get_data();
171-
$this->assertTrue( in_array( $private_comment, wp_list_pluck( $collection_data, 'id' ) ) );
171+
$this->assertTrue( in_array( $private_comment, wp_list_pluck( $collection_data, 'id' ), true ) );
172172
}
173173

174174
public function test_get_items_with_invalid_post() {
@@ -185,7 +185,7 @@ public function test_get_items_with_invalid_post() {
185185
$this->assertEquals( 200, $response->get_status() );
186186

187187
$collection_data = $response->get_data();
188-
$this->assertFalse( in_array( $comment_id, wp_list_pluck( $collection_data, 'id' ) ) );
188+
$this->assertFalse( in_array( $comment_id, wp_list_pluck( $collection_data, 'id' ), true ) );
189189

190190
wp_delete_comment( $comment_id );
191191
}
@@ -204,7 +204,7 @@ public function test_get_items_with_invalid_post_permission() {
204204
$this->assertEquals( 200, $response->get_status() );
205205

206206
$collection_data = $response->get_data();
207-
$this->assertTrue( in_array( $comment_id, wp_list_pluck( $collection_data, 'id' ) ) );
207+
$this->assertTrue( in_array( $comment_id, wp_list_pluck( $collection_data, 'id' ), true ) );
208208

209209
wp_delete_comment( $comment_id );
210210
}
@@ -296,13 +296,13 @@ public function test_get_items_exclude_query() {
296296
$request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
297297
$response = $this->server->dispatch( $request );
298298
$data = $response->get_data();
299-
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
300-
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
299+
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
300+
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
301301
$request->set_param( 'exclude', array( $id2 ) );
302302
$response = $this->server->dispatch( $request );
303303
$data = $response->get_data();
304-
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
305-
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
304+
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
305+
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
306306
}
307307

308308
public function test_get_items_offset_query() {

tests/test-rest-posts-controller.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ public function test_get_items_exclude_query() {
180180
$request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
181181
$response = $this->server->dispatch( $request );
182182
$data = $response->get_data();
183-
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
184-
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
183+
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
184+
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
185185
$request->set_param( 'exclude', array( $id2 ) );
186186
$response = $this->server->dispatch( $request );
187187
$data = $response->get_data();
188-
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
189-
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
188+
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
189+
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
190190
}
191191

192192
public function test_get_items_search_query() {

tests/test-rest-tags-controller.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ public function test_get_items_exclude_query() {
116116
$request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
117117
$response = $this->server->dispatch( $request );
118118
$data = $response->get_data();
119-
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
120-
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
119+
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
120+
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
121121
$request->set_param( 'exclude', array( $id2 ) );
122122
$response = $this->server->dispatch( $request );
123123
$data = $response->get_data();
124-
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
125-
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
124+
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
125+
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
126126
}
127127

128128
public function test_get_items_offset_query() {

tests/test-rest-users-controller.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,13 @@ public function test_get_items_exclude_query() {
403403
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
404404
$response = $this->server->dispatch( $request );
405405
$data = $response->get_data();
406-
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
407-
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
406+
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
407+
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
408408
$request->set_param( 'exclude', array( $id2 ) );
409409
$response = $this->server->dispatch( $request );
410410
$data = $response->get_data();
411-
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
412-
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
411+
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
412+
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
413413
}
414414

415415
public function test_get_items_search() {

0 commit comments

Comments
 (0)
0