Skip to content

Commit

Permalink
Fix/dont iteate m or top, dont loop too many times (#216)
Browse files Browse the repository at this point in the history
* bump

* fix(core): adds resilience for circular references
  • Loading branch information
georgejecook authored Feb 21, 2023
1 parent ac533d7 commit 24f60d8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
16 changes: 14 additions & 2 deletions bsc-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [5.4.0](https://github.com/georgejecook/rooibos/compare/5.3.5...5.4.0)
#### [5.4.1](https://github.com/georgejecook/rooibos/compare/5.4.0...5.4.1)

- Renames global timer var for uniqueness [`#211`](https://github.com/georgejecook/rooibos/pull/211)
- bump [`4889580`](https://github.com/georgejecook/rooibos/commit/48895803ea3c503b9fc7d139ade3269f061767e0)

#### [5.4.0](https://github.com/georgejecook/rooibos/compare/5.3.6...5.4.0)

> 21 February 2023
- Fix/crash stagingdir [`#215`](https://github.com/georgejecook/rooibos/pull/215)
- bump [`ddb57d4`](https://github.com/georgejecook/rooibos/commit/ddb57d40c256e002dfb2e442a1c69dfec2222693)

#### [5.3.6](https://github.com/georgejecook/rooibos/compare/5.3.5...5.3.6)

> 26 January 2023
- Renames global timer var for uniqueness [`#211`](https://github.com/georgejecook/rooibos/pull/211)
- bump [`445521b`](https://github.com/georgejecook/rooibos/commit/445521ba8801731fd628f3aab922cf74116ee509)

#### [5.3.5](https://github.com/georgejecook/rooibos/compare/5.3.4...5.3.5)
Expand Down
4 changes: 2 additions & 2 deletions bsc-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rooibos-roku",
"version": "5.4.0",
"version": "5.4.1",
"description": "simple, flexible, fun brightscript test framework for roku scenegraph apps - roku brighterscript plugin",
"repository": {
"type": "git",
Expand Down Expand Up @@ -110,4 +110,4 @@
"ts"
]
}
}
}
35 changes: 24 additions & 11 deletions framework/src/source/CommonUtils.bs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,11 @@ namespace rooibos.Common
' * @param {Boolean} caseSensitive - indicates if comparisons are case sensitive
' * @returns {Integer} - element index if array contains a value, else return -1
' */
function findElementIndexInArray(array, value, compareAttribute = invalid, caseSensitive = false) as integer
function findElementIndexInArray(array, value, compareAttribute = invalid, caseSensitive = false, callCount = 0) as integer
if callCount = 0 and not Rooibos.Common.isArray(array)
array = Rooibos.Common.asArray(array)
end if

if Rooibos.Common.isArray(array)
for i = 0 to Rooibos.Common.asArray(array).Count() - 1
compareValue = array[i]
Expand All @@ -532,7 +536,7 @@ namespace rooibos.Common
compareValue = compareValue.lookupCI(compareAttribute)
end if

if Rooibos.Common.eqValues(compareValue, value)
if Rooibos.Common.eqValues(compareValue, value, callCount + 1)
return i
end if
next
Expand Down Expand Up @@ -638,7 +642,12 @@ namespace rooibos.Common
' * @param {Dynamic} Value2 - second item to compare
' * @returns {boolean} - True if values are equal or False in other case.
' */
function eqValues(Value1, Value2, fuzzy = false) as dynamic
function eqValues(Value1, Value2, fuzzy = false, callCount = 0) as dynamic
if callCount > 10
? "REACHED MAX ITERATIONS DOING COMPARISON"
return true
end if

' Workaraund for bug with string boxing, and box everything else
val1Type = Rooibos.Common.getSafeType(Value1)
val2Type = Rooibos.Common.getSafeType(Value2)
Expand All @@ -660,11 +669,11 @@ namespace rooibos.Common
valtype = val1Type

if val1Type = "List"
return Rooibos.Common.eqArray(Value1, Value2, fuzzy)
return Rooibos.Common.eqArray(Value1, Value2, fuzzy, callCount + 1)
else if valtype = "roAssociativeArray"
return Rooibos.Common.eqAssocArray(Value1, Value2, fuzzy)
return Rooibos.Common.eqAssocArray(Value1, Value2, fuzzy, callCount + 1)
else if valtype = "roArray"
return Rooibos.Common.eqArray(Value1, Value2, fuzzy)
return Rooibos.Common.eqArray(Value1, Value2, fuzzy, callCount + 1)
else if valtype = "roSGNode"
if val2Type <> "roSGNode"
return false
Expand Down Expand Up @@ -713,7 +722,7 @@ namespace rooibos.Common
' * @param {Dynamic} Value2 - second associative array
' * @returns {boolean} - True if arrays are equal or False in other case.
' */
function eqAssocArray(Value1, Value2, fuzzy = false) as dynamic
function eqAssocArray(Value1, Value2, fuzzy = false, callCount = 0) as dynamic
l1 = Value1.Count()
l2 = Value2.Count()

Expand All @@ -727,7 +736,7 @@ namespace rooibos.Common
if rooibos.common.canSafelyIterateAAKey(Value1, k) and rooibos.common.canSafelyIterateAAKey(Value2, k)
v1 = Value1[k]
v2 = Value2[k]
if not Rooibos.Common.eqValues(v1, v2, fuzzy)
if not Rooibos.Common.eqValues(v1, v2, fuzzy, callCount + 1)
return false
end if
end if
Expand All @@ -738,7 +747,7 @@ namespace rooibos.Common
end function

function canSafelyIterateAAKey(aa, key) as boolean
if lcase(key) = "__rooibosskipfields" or key = "__mocks" or key = "__stubs" 'fix infinite loop/box crash when doing equals on an aa with a mock
if lcase(key) = "__rooibosskipfields" or key = "__mocks" or key = "__stubs" or key = "log" or key = "top" or key = "m" 'fix infinite loop/box crash when doing equals on an aa with a mock
return false
else if aa.__rooibosSkipFields <> invalid and aa.__rooibosSkipFields.doesExist(key)
return false
Expand All @@ -757,7 +766,11 @@ namespace rooibos.Common
' * @param {Dynamic} Value2 - second array
' * @returns {boolean} - True if arrays are equal or False in other case.
' */
function eqArray(Value1, Value2, fuzzy = false) as dynamic
function eqArray(Value1, Value2, fuzzy = false, callCount = 0) as dynamic
if callCount > 30
? "REACHED MAX ITERATIONS DOING COMPARISON"
return true
end if
if not (Rooibos.Common.isArray(Value1)) or not Rooibos.Common.isArray(Value2)
return false
end if
Expand All @@ -771,7 +784,7 @@ namespace rooibos.Common
for i = 0 to l1 - 1
v1 = Value1[i]
v2 = Value2[i]
if not Rooibos.Common.eqValues(v1, v2, fuzzy)
if not Rooibos.Common.eqValues(v1, v2, fuzzy, callCount + 1)
return false
end if
end for
Expand Down

0 comments on commit 24f60d8

Please sign in to comment.