Skip to content

Commit 1a7ea2a

Browse files
[5.5] Add support for unicode variable names (#546)
Co-authored-by: Thor Erik <[email protected]>
1 parent f926695 commit 1a7ea2a

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/Parser/EntryParser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private static function isQuotedName(string $name)
139139
*/
140140
private static function isValidName(string $name)
141141
{
142-
return Regex::matches('~\A[a-zA-Z0-9_.]+\z~', $name)->success()->getOrElse(false);
142+
return Regex::matches('~(*UTF8)\A[\p{Ll}\p{Lu}\p{M}\p{N}_.]+\z~', $name)->success()->getOrElse(false);
143143
}
144144

145145
/**

tests/Dotenv/DotenvTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ public function testEmptyLoading()
335335
self::assertSame(['EMPTY_VAR' => null], $dotenv->load());
336336
}
337337

338+
public function testUnicodeVarNames()
339+
{
340+
$dotenv = Dotenv::createImmutable(self::$folder, 'unicodevarnames.env');
341+
$dotenv->load();
342+
self::assertSame('Skybert', $_SERVER['AlbertÅberg']);
343+
self::assertSame('2022-04-01T00:00', $_SERVER['ДатаЗакрытияРасчетногоПериода']);
344+
}
345+
338346
public function testDirectConstructor()
339347
{
340348
$repository = RepositoryBuilder::createWithDefaultAdapters()->make();

tests/Dotenv/Parser/EntryParserTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public function testNullParse()
2424
$this->checkEmptyResult($result, 'FOO');
2525
}
2626

27+
public function testUnicodeNameParse()
28+
{
29+
$result = EntryParser::parse('FOOƱ=BAZ');
30+
$this->checkPositiveResult($result, 'FOOƱ', 'BAZ');
31+
}
32+
2733
public function testQuotesParse()
2834
{
2935
$result = EntryParser::parse("FOO=\"BAR \n\"");
@@ -139,12 +145,6 @@ public function testParseInvalidName()
139145
$this->checkErrorResult($result, 'Encountered an invalid name at [FOO_ASD!].');
140146
}
141147

142-
public function testParseUnicodeName()
143-
{
144-
$result = EntryParser::parse('FOOƱ=BAZ');
145-
$this->checkErrorResult($result, 'Encountered an invalid name at [FOOƱ].');
146-
}
147-
148148
public function testParserEscapingDouble()
149149
{
150150
$result = EntryParser::parse('FOO_BAD="iiiiviiiixiiiiviiii\\a"');
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AlbertÅberg=Skybert
2+
ДатаЗакрытияРасчетногоПериода='2022-04-01T00:00'

0 commit comments

Comments
 (0)