Repository navigation
fix(radix): prevent TypeError on primitive nodes in Radix.map - #1438
Conversation
Fixes amark#1256 If `data` passed to `Radix.map` contains primitive properties (like numbers), assigning a sort property via `t[_] = ...` throws a `TypeError: Cannot create property '' on number` when running in strict mode. This change ensures primitive nodes are safely skipped.
|
AI explains this fix as follows, after the horizontal line below. I see how it prevents the error from being thrown, but I am not sure how the code should handle sorting primitive values. @amark, do you know how the code should handle sorting primitives here? The specific error I saw in the JavaScript console shows an interesting special character as the property name the code was attempting to create on a number: The explanation below seems slightly different; it says the code was attempting to create a property named What was happening: When Gun reads data from IndexedDB using Later, when The Fix: I modified the source code inside |
|
I ran my previous comment through AI, and it sycophantically explained more of how this fix is correct (below), and now it makes sense to me, because primitives are leaf nodes, so don't need to be sorted, because radix trees themselves are only sorted and searched by key, not by value (leaf). So, I count this fix as correct. Your comment for the GitHub PR is fantastic, and your observation about the My earlier explanation was slightly simplified, but we are actually both describing the exact same line of code. Let me break down why you saw
Your comment is great, and providing the exact error string you saw with |
|
Note that if(!t){ return }
if('string' == typeof t || 'number' == typeof t || 'boolean' == typeof t){ if(Radix.debug){ throw ['BUG:', radix, cb, opt, pre] } return; } |
|
(1) since I do not predict a security exploit with this PR && you attest/assert this reduces application/data bugs (aside from preventing crashes) I will be merging - THANK YOU (2) what would make me feel more comfortable though, is if you/AI could add more tests to cover or assure that this won't cause other corruption (though obviously the crash is causing its own type of corruption). (3) yes, these should all be strings/text by now, not a value (tho I can see a leaf being a value, but this should be on the key not the leaf). however i do make errors and this... seems to be in the re-structuring (not stringifying) part, so let's move forward tho (2) would be nice, but I am trusting since ci tests passed this is at least progress. also this is a good motivator for me to pause COP & KIT and work on BOOK which will replace all this RAD code. |
Fixes #1256
If
datapassed toRadix.mapcontains primitive properties (like numbers), assigning a sort property viat[_] = ...throws aTypeError: Cannot create property '' on numberwhen running in strict mode. This change ensures primitive nodes are safely skipped.