Skip to content

Commit 1f4d912

Browse files
authored
Merge pull request #1649 from WordPress-Coding-Standards/feature/alternative-functions-allow-file-get-contents-input-stream
AlternativeFunctions: allow for php://input used with file_get_contents()
2 parents 7e54b98 + 55c08d7 commit 1f4d912

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

WordPress/Sniffs/WP/AlternativeFunctionsSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,13 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content
202202
return;
203203
}
204204

205-
unset( $params );
205+
$raw_stripped = $this->strip_quotes( $params[1]['raw'] );
206+
if ( 'php://input' === $raw_stripped ) {
207+
// This is not a file, but the read-only raw data stream from the request body.
208+
return;
209+
}
210+
211+
unset( $params, $raw_stripped );
206212

207213
break;
208214
}

WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ file_get_contents(MYABSPATH . 'plugin-file.json'); // Warning.
5050
file_get_contents( MUPLUGINDIR . 'some-file.xml' ); // OK.
5151
file_get_contents( plugin_dir_path( __FILE__ ) . 'subfolder/*.conf' ); // OK.
5252
file_get_contents(WP_Upload_Dir()['path'] . 'subdir/file.inc'); // OK.
53+
file_get_contents( 'php://input' ); // OK.

0 commit comments

Comments
 (0)