Skip to content

Commit cc9ac3b

Browse files
authored
Merge pull request #246 from GunnarFarneback/fix_merge_tag
Allow duplicate keys when merge tags are used.
2 parents ffe5319 + cc59433 commit cc9ac3b

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,23 @@ jobs:
1919
os:
2020
- ubuntu-latest
2121
- windows-latest
22-
- macOS-latest
22+
- macOS-13
2323
arch:
2424
- x64
2525
- x86
2626
exclude:
27-
- os: macOS-latest
27+
- os: macOS-13
2828
arch: x86
2929
steps:
30-
- uses: actions/checkout@v2
31-
- uses: julia-actions/setup-julia@v1
30+
- uses: actions/checkout@v4
31+
- uses: julia-actions/setup-julia@v2
3232
with:
3333
version: ${{ matrix.version }}
3434
arch: ${{ matrix.arch }}
35-
- uses: actions/cache@v1
36-
env:
37-
cache-name: cache-artifacts
38-
with:
39-
path: ~/.julia/artifacts
40-
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
41-
restore-keys: |
42-
${{ runner.os }}-test-${{ env.cache-name }}-
43-
${{ runner.os }}-test-
44-
${{ runner.os }}-
35+
- uses: julia-actions/cache@v2
4536
- uses: julia-actions/julia-buildpkg@v1
4637
- uses: julia-actions/julia-runtest@v1
4738
- uses: julia-actions/julia-processcoverage@v1
48-
- uses: codecov/codecov-action@v1
39+
- uses: codecov/codecov-action@v5
4940
with:
50-
file: lcov.info
41+
files: lcov.info

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "YAML"
22
uuid = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
3-
version = "0.4.13"
3+
version = "0.4.14"
44

55

66
[deps]

src/constructor.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function construct_sequence(constructor::Constructor, node::Node)
135135
end
136136

137137

138+
# Returns true if a merge tag was used and false otherwise.
138139
function flatten_mapping(node::MappingNode)
139140
merge = []
140141
index = 1
@@ -171,12 +172,22 @@ function flatten_mapping(node::MappingNode)
171172

172173
if !isempty(merge)
173174
node.value = vcat(merge, node.value)
175+
return true
174176
end
177+
178+
return false
175179
end
176180

177181

178182
function construct_mapping(dicttype::Union{Type,Function}, constructor::Constructor, node::MappingNode; strict_unique_keys::Bool=false)
179-
flatten_mapping(node)
183+
# If the mapping was constructed with a merge tag, skip the later
184+
# test for duplicates, since it is a key part of the merging
185+
# functionality that selected values can be changed.
186+
#
187+
# (Ideally uniqueness would still be tested for the keys outside
188+
# of the merge tags, but that would require more intricate changes
189+
# to the code.)
190+
merged_mapping = flatten_mapping(node)
180191
mapping = dicttype()
181192
for (key_node, value_node) in node.value
182193
key = construct_object(constructor, key_node)
@@ -191,7 +202,7 @@ function construct_mapping(dicttype::Union{Type,Function}, constructor::Construc
191202
end
192203
end
193204
try
194-
if haskey(mapping, key)
205+
if !merged_mapping && haskey(mapping, key)
195206
strict_unique_keys ? error("Duplicate key `$(key)` detected in mapping.") : @error "Duplicate key detected in mapping" node key
196207
end
197208
mapping[key] = value

0 commit comments

Comments
 (0)