Skip to content

Commit

Permalink
[5.5] Add support for unicode variable names (#546)
Browse files Browse the repository at this point in the history
Co-authored-by: Thor Erik <219796+thorerik@users.noreply.github.com>
  • Loading branch information
GrahamCampbell and thorerik committed Oct 16, 2022
1 parent f926695 commit 1a7ea2a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Parser/EntryParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static function isQuotedName(string $name)
*/
private static function isValidName(string $name)
{
return Regex::matches('~\A[a-zA-Z0-9_.]+\z~', $name)->success()->getOrElse(false);
return Regex::matches('~(*UTF8)\A[\p{Ll}\p{Lu}\p{M}\p{N}_.]+\z~', $name)->success()->getOrElse(false);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Dotenv/DotenvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ public function testEmptyLoading()
self::assertSame(['EMPTY_VAR' => null], $dotenv->load());
}

public function testUnicodeVarNames()
{
$dotenv = Dotenv::createImmutable(self::$folder, 'unicodevarnames.env');
$dotenv->load();
self::assertSame('Skybert', $_SERVER['AlbertÅberg']);
self::assertSame('2022-04-01T00:00', $_SERVER['ДатаЗакрытияРасчетногоПериода']);
}

public function testDirectConstructor()
{
$repository = RepositoryBuilder::createWithDefaultAdapters()->make();
Expand Down
12 changes: 6 additions & 6 deletions tests/Dotenv/Parser/EntryParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public function testNullParse()
$this->checkEmptyResult($result, 'FOO');
}

public function testUnicodeNameParse()
{
$result = EntryParser::parse('FOOƱ=BAZ');
$this->checkPositiveResult($result, 'FOOƱ', 'BAZ');
}

public function testQuotesParse()
{
$result = EntryParser::parse("FOO=\"BAR \n\"");
Expand Down Expand Up @@ -139,12 +145,6 @@ public function testParseInvalidName()
$this->checkErrorResult($result, 'Encountered an invalid name at [FOO_ASD!].');
}

public function testParseUnicodeName()
{
$result = EntryParser::parse('FOOƱ=BAZ');
$this->checkErrorResult($result, 'Encountered an invalid name at [FOOƱ].');
}

public function testParserEscapingDouble()
{
$result = EntryParser::parse('FOO_BAD="iiiiviiiixiiiiviiii\\a"');
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/env/unicodevarnames.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
AlbertÅberg=Skybert
ДатаЗакрытияРасчетногоПериода='2022-04-01T00:00'

0 comments on commit 1a7ea2a

Please sign in to comment.