Skip to content

Commit

Permalink
Merge pull request #54 from rogusdev/fix-dollar-sign
Browse files Browse the repository at this point in the history
fix dollar sign parsing and bump version
  • Loading branch information
rogusdev authored Mar 2, 2021
2 parents 6cc4161 + 5baf174 commit e4a6a1b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/DotNetEnv/DotNetEnv.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<Title>DotNetEnv</Title>
<Description>A .NET library to load environment variables from .env files</Description>
<AssemblyTitle>DotNetEnv</AssemblyTitle>
<AssemblyVersion>2.1.0</AssemblyVersion>
<PackageVersion>2.1.0</PackageVersion>
<AssemblyVersion>2.1.1</AssemblyVersion>
<PackageVersion>2.1.1</PackageVersion>
<TargetFramework>netstandard1.3</TargetFramework>
<AssemblyName>DotNetEnv</AssemblyName>
<OutputType>Library</OutputType>
Expand Down
4 changes: 1 addition & 3 deletions src/DotNetEnv/IValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public class ValueActual : IValue
private readonly string _value;

public ValueActual (IEnumerable<string> strs)
{
_value = string.Join(string.Empty, strs);
}
: this(string.Join(string.Empty, strs)) {}

public ValueActual (string str)
{
Expand Down
6 changes: 5 additions & 1 deletion src/DotNetEnv/Parsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ from id in Identifier
from _c in Parse.Char('}')
select new ValueInterpolated(id);

internal static readonly Parser<IValue> JustDollarValue =
from d in DollarSign
select new ValueActual(d.ToString());

internal static readonly Parser<IValue> InterpolatedValue =
InterpolatedEnvVar.Or(InterpolatedBracesEnvVar);
InterpolatedEnvVar.Or(InterpolatedBracesEnvVar).Or(JustDollarValue);

internal static readonly Parser<string> SpecialChar =
Utf32Char
Expand Down
18 changes: 18 additions & 0 deletions test/DotNetEnv.Tests/.env_embedded
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,21 @@ FIRST_KEY=value1
SECOND_KEY=value2and$FIRST_KEY
THIRD_KEY=$EXISTING_ENVIRONMENT_VARIABLE;andvalue3
FOURTH_KEY=$DNE_VAR;nope


GROUP_FILTER_REGEX=^((?!Everyone).)*$

DOLLAR1_U=value$
DOLLAR2_U=value$DOLLAR1_U$
DOLLAR3_U=value$.$
DOLLAR4_U=value$$

DOLLAR1_S='value$'
DOLLAR2_S='value$DOLLAR1_S$'
DOLLAR3_S='value$.$'
DOLLAR4_S='value$$'

DOLLAR1_D="value$"
DOLLAR2_D="value$DOLLAR1_D$"
DOLLAR3_D="value$.$"
DOLLAR4_D="value$$"
17 changes: 17 additions & 0 deletions test/DotNetEnv.Tests/EnvTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@ public void ParseInterpolatedTest()
Assert.Equal("value;andvalue3", System.Environment.GetEnvironmentVariable("THIRD_KEY"));
// DNE_VAR does not exist (has no value)
Assert.Equal(";nope", System.Environment.GetEnvironmentVariable("FOURTH_KEY"));

Assert.Equal("^((?!Everyone).)*$", Environment.GetEnvironmentVariable("GROUP_FILTER_REGEX"));

Assert.Equal("value$", Environment.GetEnvironmentVariable("DOLLAR1_U"));
Assert.Equal("valuevalue$$", Environment.GetEnvironmentVariable("DOLLAR2_U"));
Assert.Equal("value$.$", Environment.GetEnvironmentVariable("DOLLAR3_U"));
Assert.Equal("value$$", Environment.GetEnvironmentVariable("DOLLAR4_U"));

Assert.Equal("value$", Environment.GetEnvironmentVariable("DOLLAR1_S"));
Assert.Equal("value$DOLLAR1_S$", Environment.GetEnvironmentVariable("DOLLAR2_S"));
Assert.Equal("value$.$", Environment.GetEnvironmentVariable("DOLLAR3_S"));
Assert.Equal("value$$", Environment.GetEnvironmentVariable("DOLLAR4_S"));

Assert.Equal("value$", Environment.GetEnvironmentVariable("DOLLAR1_D"));
Assert.Equal("valuevalue$$", Environment.GetEnvironmentVariable("DOLLAR2_D"));
Assert.Equal("value$.$", Environment.GetEnvironmentVariable("DOLLAR3_D"));
Assert.Equal("value$$", Environment.GetEnvironmentVariable("DOLLAR4_D"));
}

[Fact]
Expand Down

0 comments on commit e4a6a1b

Please sign in to comment.