Skip to content

Trimed values #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ protected function sanitiseVariableValue($name, $value)
}
}

return array($name, trim($value));
return array($name, $value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function notEmpty()
{
return $this->assertCallback(
function ($value) {
return strlen(trim($value)) > 0;
return strlen($value) > 0;
},
'is empty'
);
Expand Down
27 changes: 2 additions & 25 deletions tests/Dotenv/DotenvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function testDotenvAssertions()
$dotenv->load();
$this->assertSame('val1', getenv('ASSERTVAR1'));
$this->assertEmpty(getenv('ASSERTVAR2'));
$this->assertEmpty(getenv('ASSERTVAR3'));
$this->assertSame('val3 ', getenv('ASSERTVAR3'));
$this->assertSame('0', getenv('ASSERTVAR4'));

$dotenv->required(array(
Expand All @@ -271,6 +271,7 @@ public function testDotenvAssertions()

$dotenv->required(array(
'ASSERTVAR1',
'ASSERTVAR3',
'ASSERTVAR4',
))->notEmpty();

Expand All @@ -295,30 +296,6 @@ public function testDotenvEmptyThrowsRuntimeException()
$dotenv->required('ASSERTVAR2')->notEmpty();
}

/**
* @expectedException \Dotenv\Exception\ValidationException
* @expectedExceptionMessage One or more environment variables failed assertions: ASSERTVAR3 is empty.
*/
public function testDotenvStringOfSpacesConsideredEmpty()
{
$dotenv = new Dotenv($this->fixturesFolder, 'assertions.env');
$dotenv->load();
$this->assertEmpty(getenv('ASSERTVAR3'));

$dotenv->required('ASSERTVAR3')->notEmpty();
}

/**
* @expectedException \Dotenv\Exception\ValidationException
* @expectedExceptionMessage One or more environment variables failed assertions: ASSERTVAR3 is empty.
*/
public function testDotenvHitsLastChain()
{
$dotenv = new Dotenv($this->fixturesFolder, 'assertions.env');
$dotenv->load();
$dotenv->required('ASSERTVAR3')->notEmpty();
}

/**
* @expectedException \Dotenv\Exception\ValidationException
* @expectedExceptionMessage One or more environment variables failed assertions: foo is missing.
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/env/assertions.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ASSERTVAR1="val1"
ASSERTVAR2=""
ASSERTVAR3=" "
ASSERTVAR3="val3 "
ASSERTVAR4="0" # empty looking value