[Bug]: Decoder does not restore the parent value after decoding a child
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 88/100
Direzione di ricerca
Inizia in XCJSON.Decoder.decode(_:pathComponent:) e verifica come lo stato del decoder venga salvato e ripristinato durante la decodifica degli elementi figlio. Aggiungi il test di regressione in Sources/Tests/DecoderStateTests.swift, quindi esegui swift test --filter restoresParentValueAfterDecodingChild. Il lavoro è completo quando l’oggetto padre rimane un oggetto e il suo contenitore keyed può essere riaperto dopo la decodifica dell’elemento figlio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
In XCJSON.Decoder.decode(_:pathComponent:), oldCurrentValue captures the incoming child value rather than the decoder's existing currentValue:
let oldCurrentValue = value
defer {
currentValue = oldCurrentValue
}
As a result, after decoding a child, currentPath is restored to the parent path, but currentValue still refers to the child.
Observed on main at c132630aabf40f6d6c3f7bb004595d2e5a28ea42.
Steps to reproduce
The following can be added to the existing library test target, which has access to the package-scoped decoder:
import Foundation
import Testing
import XcodeProjectFormat
private struct ParentValueProbe: XCJSON.Decodable {
init(with coder: XCJSON.Decoder) throws {
let container = try coder.openKeyedContainer()
let _: String = try container.decode("name")
#expect(coder.currentNodeType == .object)
_ = try coder.openKeyedContainer()
}
}
@Test func restoresParentValueAfterDecodingChild() throws {
let _: ParentValueProbe = try XCJSON.Decoder.decode(
data: Data(#"{"name":"App"}"#.utf8)
)
}
Save the test as Sources/Tests/DecoderStateTests.swift, then run from the repository root:
swift test --filter restoresParentValueAfterDecodingChild
Expected behavior
If the decoder is intended to restore its parent context after decoding a child, currentNodeType should remain .object, and reopening the parent's keyed container should succeed.
Actual behavior
After decoding name, the current node is a string. Reopening the keyed container throws:
Expected an instance of dictionary but an instance string was specified
Stack trace
N/A — this produces an assertion failure and a thrown error, not a crash.
Environment
- Version: main at c132630aabf40f6d6c3f7bb004595d2e5a28ea42
- OS: macOS 26.6.2 (25G83), Apple silicon (arm64)
- Swift version: Apple Swift 6.4 (swiftlang-6.4.0.34.1)
- Xcode: 27.2 beta (27B5019j)
Additional context
I reproduced this with a standalone probe against the library, but have not found an existing public Project decoding case affected by it. Existing decoding implementations that retain their original container may not encounter the issue.
Is restoring the parent value the intended behavior? If so, changing the saved value to currentValue appears to address it. I would be happy to submit a focused fix with regression tests covering restoration after both successful and throwing child decodes.
- Lingua principale
- Swift
- Stelle
- 384
- Fork
- 12
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apple/xcode-project-format
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
apple/xcode-project-format#7 · 1 reazione ·
Tutte le issue di apple/xcode-project-format
Issue simili
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
type: docs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
googleapis/google-cloud-swift#971 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
bitcoindevkit/bdk-ffi#1125 ·
-
Move wallpaper setting Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
mozilla-mobile/firefox-ios#35743 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
manaflow-ai/cmux#13417 ·