# new test for php://input and patch for small flaw in run-tests.php

- Thread: https://externals.io/message/28062
- Original archive: https://news-web.php.net/php.internals/28062
- Started by Gregory Beaver on 2007-02-17T04:24:44+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #28062 — Gregory Beaver — 2007-02-17T04:24:44+00:00

URL: https://externals.io/message/28062#28062

Hi all,

While porting improvements of run-tests.php into the pear run-tests
command, I noticed that there are no tests for the php://input stream in
PHP_5_2 (didn't look at HEAD yet), so I thought I would offer one if it
is useful.

At the same time, I found a flaw in the implementation of POST_RAW,
patch attached.  Basically, \n is appended to all lines including the
last line.  The patch corrects this by appending \n to all but the last
line so there is no trailing whitespace.

Here's the new test:

--TEST--
php://input
--SKIPIF--
<?php if (php_sapi_name()=='cli') die('skip'); ?>
--POST_RAW--
Content-Type: application/x-www-form-urlencoded
userid=joe&password=guessme
--FILE--
<?php
var_dump($_FILES);
var_dump($_POST);
$fp = fopen('php://input', 'r');
$a = fread($fp, 8192);
fclose($fp);
var_dump($a);
?>
--EXPECT--
array(0) {
}
array(2) {
  ["userid"]=>
  string(3) "joe"
  ["password"]=>
  string(7) "guessme"
}
string(27) "userid=joe&password=guessme"
