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

Commit faad2c3

Browse files
committed
Fixing array_filter() that was too bread with 0 as a version number
1 parent 3a43e3c commit faad2c3

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

php/src/UAParser/Result/AbstractVersionedSoftware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ public function toString()
2323
/** @return string */
2424
protected function formatVersion()
2525
{
26-
return join('.', array_filter(func_get_args()));
26+
return join('.', array_filter(func_get_args(), 'is_numeric'));
2727
}
2828
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* ua-parser
4+
*
5+
* Copyright (c) 2011-2012 Dave Olsen, http://dmolsen.com
6+
*
7+
* Released under the MIT license
8+
*/
9+
namespace UAParser\Tests\Result;
10+
11+
use PHPUnit_Framework_TestCase as AbstractTestCase;
12+
use UAParser\Result\UserAgent;
13+
14+
class UserAgentTest extends AbstractTestCase
15+
{
16+
/** @var UserAgent */
17+
private $userAgent;
18+
19+
public function setUp()
20+
{
21+
$this->userAgent = new UserAgent();
22+
}
23+
24+
public function testBugWith0InVersion()
25+
{
26+
$this->userAgent->major = 0;
27+
$this->userAgent->minor = 0;
28+
$this->userAgent->patch = 0;
29+
30+
$this->assertSame('0.0.0', $this->userAgent->toVersion());
31+
$this->assertSame('Other 0.0.0', $this->userAgent->toString());
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* ua-parser
4+
*
5+
* Copyright (c) 2011-2012 Dave Olsen, http://dmolsen.com
6+
*
7+
* Released under the MIT license
8+
*/
9+
namespace UAParser\Tests\Result;
10+
11+
use PHPUnit_Framework_TestCase as AbstractTestCase;
12+
use UAParser\Result\OperatingSystem;
13+
14+
class OperatingSystemTest extends AbstractTestCase
15+
{
16+
/** @var OperatingSystem */
17+
private $operatingSystem;
18+
19+
public function setUp()
20+
{
21+
$this->operatingSystem = new OperatingSystem();
22+
}
23+
24+
public function testBugWith0InVersion()
25+
{
26+
$this->operatingSystem->major = 0;
27+
$this->operatingSystem->minor = 0;
28+
$this->operatingSystem->patch = 0;
29+
$this->operatingSystem->patchMinor = 0;
30+
31+
$this->assertSame('0.0.0.0', $this->operatingSystem->toVersion());
32+
$this->assertSame('Other 0.0.0.0', $this->operatingSystem->toString());
33+
}
34+
}

0 commit comments

Comments
 (0)