Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix equality check of oneOf decoder #905

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/Elm/Kernel/Json.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ function _Json_equality(x, y)
return x.index === y.index && _Json_equality(x.decoder, y.decoder);

case __1_MAP:
return x.func === y.func && _Json_listEquality(x.decoders, y.decoders);
return x.func === y.func && _Json_arrayEquality(x.decoders, y.decoders);

case __1_AND_THEN:
return x.callback === y.callback && _Json_equality(x.decoder, y.decoder);
Expand All @@ -380,7 +380,7 @@ function _Json_equality(x, y)
}
}

function _Json_listEquality(aDecoders, bDecoders)
function _Json_arrayEquality(aDecoders, bDecoders)
{
var len = aDecoders.length;
if (len !== bDecoders.length)
Expand All @@ -397,6 +397,30 @@ function _Json_listEquality(aDecoders, bDecoders)
return true;
}

function _Json_listEquality(aDecoders, bDecoders)
{
var tempA = aDecoders;
var tempB = bDecoders;
while (tempA.$ !== '[]')
{
if (tempB.$ === '[]')
{
return false;
}
if (!_Json_equality(tempA.a, tempB.a))
{
return false;
}
tempA = tempA.b;
tempB = tempB.b;
}
if (tempB.$ !== '[]')
{
return false;
}
return true;
}


// ENCODE

Expand Down