Skip to content

Commit 71f5a6f

Browse files
committed
Allow - values for %O and %I
1 parent ebde075 commit 71f5a6f

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
## [Unreleased]
88
### Modified
99
- Replace psalm with phpstan
10+
- Allow `-` values for `%O` and `%I`: https://github.com/kassner/log-parser/issues/66
1011

1112
## [2.1.1] - 2023-07-18
1213
### Added

src/LogParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ final class LogParser
3939
'%>s' => '(?P<status>\d{3}|-)',
4040
'%b' => '(?P<responseBytes>(\d+|-))',
4141
'%T' => '(?P<requestTime>(\d+\.?\d*))',
42-
'%O' => '(?P<sentBytes>[0-9]+)',
43-
'%I' => '(?P<receivedBytes>[0-9]+)',
42+
'%O' => '(?P<sentBytes>(\d+|-))',
43+
'%I' => '(?P<receivedBytes>(\d+|-))',
4444
'\%\{(?P<name>[a-zA-Z]+)(?P<name2>[-]?)(?P<name3>[a-zA-Z]+)\}i' => '(?P<Header\\1\\3>.*?)',
4545
'%D' => '(?P<timeServeRequest>[0-9]+)',
4646
'%S' => '(?P<scheme>http|https)',

tests/Format/BytesReceivedTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Kassner\LogParser\Tests\Format;
44

55
use Kassner\LogParser\LogParser;
6-
use Kassner\LogParser\Tests\Provider\PositiveInteger as PositiveIntegerProvider;
6+
use Kassner\LogParser\Tests\Provider\NullableInteger as NullableIntegerProvider;
77

88
/**
99
* @format %I
1010
*
1111
* @description Bytes received, including request and headers, cannot be zero. You need to enable mod_logio to use this.
1212
*/
13-
class BytesReceivedTest extends PositiveIntegerProvider
13+
class BytesReceivedTest extends NullableIntegerProvider
1414
{
1515
protected $parser;
1616

tests/Format/BytesSentTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Kassner\LogParser\Tests\Format;
44

55
use Kassner\LogParser\LogParser;
6-
use Kassner\LogParser\Tests\Provider\PositiveInteger as PositiveIntegerProvider;
6+
use Kassner\LogParser\Tests\Provider\NullableInteger as NullableIntegerProvider;
77

88
/**
99
* @format %O
1010
*
1111
* @description Bytes sent, including headers, cannot be zero. You need to enable mod_logio to use this.
1212
*/
13-
class BytesSentTest extends PositiveIntegerProvider
13+
class BytesSentTest extends NullableIntegerProvider
1414
{
1515
protected $parser;
1616

tests/Provider/NullableInteger.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Kassner\LogParser\Tests\Provider;
4+
5+
class NullableInteger extends \PHPUnit\Framework\TestCase
6+
{
7+
public function successProvider()
8+
{
9+
return [
10+
['1'],
11+
['1234'],
12+
['99999999'],
13+
['100000000000000000000000'],
14+
['0'],
15+
['-'],
16+
];
17+
}
18+
19+
public function invalidProvider()
20+
{
21+
return [
22+
['-1'],
23+
['dummy 1234'],
24+
['lala'],
25+
['-100000000000000000000000'],
26+
['12.34'],
27+
['0.0'],
28+
['-0'],
29+
];
30+
}
31+
}

0 commit comments

Comments
 (0)