From 5e1711f229eae915b9917ea87109946b9df59bc4 Mon Sep 17 00:00:00 2001 From: LiHS Date: Tue, 25 Jan 2022 10:33:28 +0800 Subject: [PATCH] fix header isValidKeyName #374 --- src/Qiniu/Http/Header.php | 2 +- tests/Qiniu/Tests/HeaderTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Qiniu/Http/Header.php b/src/Qiniu/Http/Header.php index cc35d9a7..2bf65c21 100644 --- a/src/Qiniu/Http/Header.php +++ b/src/Qiniu/Http/Header.php @@ -264,7 +264,7 @@ public function count() */ private static function isValidKeyName($str) { - for ($i = 0; $i < count($str); $i += 1) { + for ($i = 0; $i < strlen($str); $i += 1) { if (!isset(self::$isTokenTable[$str[$i]])) { return false; } diff --git a/tests/Qiniu/Tests/HeaderTest.php b/tests/Qiniu/Tests/HeaderTest.php index 669771c7..b7ecd1f9 100644 --- a/tests/Qiniu/Tests/HeaderTest.php +++ b/tests/Qiniu/Tests/HeaderTest.php @@ -40,6 +40,20 @@ public function testNormalizeKey() $this->assertEquals($actual, $except); } + + public function testInvalidKeyName() + { + $except = array( + 'a:x-test-1', + ); + + $actual = array_map(function ($str) { + return Header::normalizeKey($str); + }, $except); + + $this->assertEquals($except, $actual); + } + public function testGetRawData() { $header = new Header($this->heads);