Skip to content

Commit

Permalink
AMFDictionary: fix true == 1 issue on cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtynjala committed Oct 11, 2022
1 parent 7ca0040 commit f3c05a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/feathers/amfio/AMFDictionary.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ abstract AMFDictionary<K, V>(AMFDictionaryData<K, V>) from AMFDictionaryData<K,
var keys = @:privateAccess this.keys;
var values = @:privateAccess this.values;
var index = keys.indexOf(key);
#if cpp
// seems like a bug in hxcpp where 1 == true
if (index != -1 && (key is Bool) || (key is Int)) {
do {
var oldKey = keys[index];
if (Std.string(oldKey) == Std.string(key)) {
break;
}
index = keys.indexOf(key, index + 1);
} while (index != -1);
}
#end
if (index == -1) {
return null;
}
Expand All @@ -76,6 +88,15 @@ abstract AMFDictionary<K, V>(AMFDictionaryData<K, V>) from AMFDictionaryData<K,
var keys = @:privateAccess this.keys;
var values = @:privateAccess this.values;
var index = keys.indexOf(key);
#if cpp
// seems like a bug in hxcpp where 1 == true
if (index != -1 && (key is Bool) || (key is Int)) {
var oldKey = keys[index];
if (Std.string(oldKey) != Std.string(key)) {
index = -1;
}
}
#end
if (index == -1) {
index = keys.length;
keys.push(key);
Expand Down
2 changes: 2 additions & 0 deletions test/src/feathers/amfio/AMFDictionaryTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AMFDictionaryTest extends Test {
}

public function testGetAndSet():Void {
trace("*** START");
var dict = new AMFDictionary<Dynamic, Dynamic>();
dict[1] = "number";
dict["two"] = "string";
Expand All @@ -35,5 +36,6 @@ class AMFDictionaryTest extends Test {
Assert.equals("object", dict[obj]);
Assert.equals("class", dict[Test]);
Assert.isNull(dict["abc123"]);
trace("*** END");
}
}

0 comments on commit f3c05a4

Please sign in to comment.