Skip to content

Commit 6cbc4bb

Browse files
IgorFedchenkoAaronontheweb
authored andcommitted
Fix removing substitutions that are still to be resolved (#142)
* Added failing test * Fixed related test * Fixed removing of valid substitutions
1 parent f7806c2 commit 6cbc4bb

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/Hocon.Tests/HoconTests.cs

+32
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Collections.Generic;
1010
using System.Linq;
1111
using System.Threading.Tasks;
12+
using FluentAssertions;
1213
using Xunit;
1314
using Xunit.Abstractions;
1415

@@ -326,6 +327,37 @@ public void CanAssignValuesToPathExpressions()
326327
Assert.Equal(3L, config.GetLong("a.b.e.f"));
327328
}
328329

330+
[Fact]
331+
public void Fix_substitutions_Issue123()
332+
{
333+
var hocon = @"
334+
a: avalue
335+
336+
b {
337+
b1: ""0001-01-01Z""
338+
b2: 0
339+
b_alpha: ${a}/${c.c1}/${b.b3}/${b.b4}
340+
b_beta: ""[""${b.b_alpha}"",""${b.b1}"",""${b.b2}""]""
341+
}
342+
343+
c {
344+
c1: c1value
345+
}
346+
347+
b {
348+
b3: b4value
349+
}
350+
351+
b {
352+
b4: b4value
353+
}
354+
";
355+
356+
var config = Parser.Parse(hocon);
357+
config.GetString("b.b_alpha").Should().Be("avalue/c1value/b4value/b4value");
358+
config.GetString("b.b_beta").Should().Be("[avalue/c1value/b4value/b4value,0001-01-01Z,0]");
359+
}
360+
329361
[Fact]
330362
public void CanAssignLongToField()
331363
{

src/Hocon.Tests/SelfReferentialSubstitution.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ public void HiddenSubstitutionShouldNeverBeEvaluated()
186186
{
187187
var hocon = @"
188188
foo : ${does-not-exist}
189-
foo : 42";
189+
foo : 42
190+
bar : ${yet-another-to-ignore}
191+
bar : [42]
192+
";
190193

191194
HoconRoot config = null;
192195
var ex = Record.Exception(() => config = Parser.Parse(hocon));

src/Hocon/Impl/HoconField.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ internal void SetValue(HoconValue value)
9696
if (value == null)
9797
return;
9898

99-
if (value.Type == HoconType.Literal)
99+
if (value.Type != HoconType.Object)
100100
{
101101
foreach (var item in _internalValues)
102102
{
103103
var subs = item.GetSubstitutions();
104-
foreach (var sub in subs)
104+
var preservedSub = value.GetSubstitutions();
105+
foreach (var sub in subs.Except(preservedSub))
105106
{
106107
sub.Removed = true;
107108
}

0 commit comments

Comments
 (0)