Lix JSON parser silently accepts duplicate object keys #1162
Labels
No labels
Affects/CppNix
Affects/Nightly
Affects/Only nightly
Affects/Stable
Area/build-packaging
Area/cli
Area/evaluator
Area/fetching
Area/flakes
Area/language
Area/lix ci
Area/nix-eval-jobs
Area/profiles
Area/protocol
Area/releng
Area/remote-builds
Area/repl
Area/repl/debugger
Area/store
awaiting
author
awaiting
contributors
bug
Context
contributors
Context
drive-by
Context
maintainers
Context
RFD
crash 💥
Cross Compilation
devx
docs
Downstream Dependents
E/easy
E/hard
E/help wanted
E/reproducible
E/requires rearchitecture
Feature/S3
Importance
High
Importance
Low
imported
Language/Bash
Language/C++
Language/NixLang
Language/Python
Language/Rust
Needs Langver
OS/Linux
OS/macOS
performance
regression
Release Blocking
Non-urgent
Release Blocking
Urgent
stability
Status
blocked
Status
invalid
Status
postponed
Status
wontfix
testing
testing/flakey
Topic/Large Scale Installations
Urgency
High
Urgency
Low
ux
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lix-project/lix#1162
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Describe the bug
Lix's JSON parser used by
builtins.fromJSONsilently accepts duplicate object keys, discarding all values but the last.Steps To Reproduce
Expected behavior
Such unusual JSON input should be rejected, or if not, the current behavior should be at least tested for.
nix --versionoutputAdditional context
The existing behavior is defined by
JSONObjectStateinlix/libexpr/json-to-value.ccclass JSONObjectState : public JSONState {using JSONState::JSONState;GcMap<Symbol, Value> attrs;Symbol _key;std::unique_ptr<JSONState> resolve(EvalState & state) override{auto attrs2 = state.ctx.buildBindings(attrs.size());for (auto & i : attrs)attrs2.insert(i.first, i.second);parent->value() = {NewValueAs::attrs, attrs2.alreadySorted()};return std::move(parent);}void add() override{attrs.insert_or_assign(_key, value());v = nullptr;}public:void key(string_t & name, EvalState & state){_key = state.ctx.symbols.create(name);}};Since I'm already in the weeds in the JSON parser I'm happy to drive a fix, but that first requires determining how this will be fixed. This would be a breaking change. Would we want to warn first before making it an error? Would we need to add a flag to re-enable old behavior?