Skip to content

Commit 659edf1

Browse files
authored
Merge pull request #84 from os-cillation/master
String Values had no quotes
2 parents c408340 + e3d40ad commit 659edf1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Tests/Types/ValueTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public function create() {
4242
$this->assertSame(1.01, Value::create('1.01'));
4343
$this->assertSame('hello', Value::create('hello'));
4444
$this->assertSame('hello', Value::create('"hello"'));
45+
$this->assertSame('hello', Value::create('\'hello\''));
46+
$this->assertSame('hello', Value::create('`hello`'));
47+
$this->assertSame('\'hello"', Value::create('\'hello"'));
48+
49+
$encoded = '{"test":true}';
50+
51+
$this->assertSame($encoded, Value::create("\"{$encoded}\""));
52+
$this->assertSame($encoded, Value::create("{$encoded}"));
4553

4654
$this->assertSame(true, Value::create('true'));
4755
$this->assertSame(false, Value::create('false'));

Types/Value.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static function create($value) {
4545
if($value === 'false') return false;
4646
if($value === 'null') return null;
4747

48-
$unquoted = preg_replace('/\"|\\\'|\`$/', '', preg_replace('/^\"|\\\'|\`/', '', $value));
48+
$unquoted = preg_replace('/^(?|\"(.*)\"|\\\'(.*)\\\'|\`(.*)\`)$/', '$1', $value);
4949
if (!is_numeric($unquoted)) return $unquoted;
5050
if ((string) intval($unquoted) === $unquoted) return intval($unquoted);
5151

0 commit comments

Comments
 (0)