Skip to content

Commit d06cf7c

Browse files
iron9lightArkatufus
authored andcommitted
Fix a bug when getting a string containing a substitution as an array element (#88)
1 parent ef70a15 commit d06cf7c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Hocon.Tests/Substitution.cs

+29
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,35 @@ public void CanConcatenateQuotedString()
171171
Assert.Equal("Hello my name is Roger", Parser.Parse(hocon).GetString("a.c"));
172172
}
173173

174+
/*
175+
* FACT:
176+
* To get a string containing a substitution as an array element,
177+
* you must use value concatenation with the substitution in the unquoted portion
178+
*/
179+
[Fact]
180+
public void CanConcatenateUnquotedStringOfArrayElement()
181+
{
182+
var hocon = @"a {
183+
name = Roger
184+
c = [Hello my name is ${a.name}]
185+
}";
186+
Assert.Equal("Hello my name is Roger", Parser.Parse(hocon).GetStringList("a.c")[0]);
187+
}
188+
189+
/*
190+
* FACT:
191+
* or can use value concatenation of a substitution and a quoted string.
192+
*/
193+
[Fact]
194+
public void CanConcatenateQuotedStringOfArrayElement()
195+
{
196+
var hocon = @"a {
197+
name = Roger
198+
c = [""Hello my name is ""${a.name}]
199+
}";
200+
Assert.Equal("Hello my name is Roger", Parser.Parse(hocon).GetStringList("a.c")[0]);
201+
}
202+
174203
/*
175204
* FACT:
176205
* Substitutions are resolved by looking up the path in the configuration.

src/Hocon/Impl/HoconValue.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,10 @@ internal void ResolveValue(IHoconElement child)
640640
$"Sibling type:{Type}, substitution type:{child.Type}");
641641
}
642642

643-
((HoconField) Parent).ResolveValue(this);
643+
if (Parent is HoconField hoconField)
644+
{
645+
hoconField.ResolveValue(this);
646+
}
644647
}
645648

646649
/// <summary>

0 commit comments

Comments
 (0)