Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
🐛 keep substituted values when concatenating to a substitueed array w…
Browse files Browse the repository at this point in the history
…ith += #27
  • Loading branch information
mockersf committed Aug 25, 2020
1 parent fc0aa01 commit 2282f87
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/internals/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ impl HoconInternal {
.collect(),
)
}
HoconValue::PathSubstitution { ref target, .. } => {
let value = concatenated_arrays
.get(&target.to_path())
.cloned()
.unwrap_or_else(HashMap::new);
concatenated_arrays
.entry(full_path.clone())
.or_insert(value);
(item.substitute(config, &root, &full_path), full_path)
}
v => {
let mut checked_path: Path = vec![];
for item in full_path.clone() {
Expand Down Expand Up @@ -373,6 +383,7 @@ impl HoconInternal {
match (exist, first_key) {
(_, Some(HoconValue::Integer(0)))
if path_item == HoconValue::Integer(0)
&& last_path_encoutered.len() >= current_path.len()
&& current_path.as_slice()
!= &last_path_encoutered[0..current_path.len()] =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/internals/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl HoconValue {
}
}

fn to_path(&self) -> Vec<HoconValue> {
pub(crate) fn to_path(&self) -> Vec<HoconValue> {
match self {
HoconValue::UnquotedString(s) if s == "." => vec![],
HoconValue::UnquotedString(s) => s
Expand Down
9 changes: 9 additions & 0 deletions tests/data/issue-27.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"array1": [1, 2],
"v": ${array1}
"v" += "v3"

"w": [1, 2]
"w" += "w3"

}
5 changes: 5 additions & 0 deletions tests/snapshots/snapshot__issue-27.conf.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: tests/snapshot.rs
expression: stable_readable_display(&doc)
---
"{array1: [1, 2], v: [1, 2, \"v3\"], w: [1, 2, \"w3\"]}"

0 comments on commit 2282f87

Please sign in to comment.