#304 √ invalid
tc

Hash constructor incorrectly converts empty array to Hash

Reported by tc | August 26th, 2008 @ 07:17 AM

When creating a Hash from an empty Array the Hash constructor (maybe Object.clone) creates the Hash based on the internal Array class keys and values.

I expect $H([]).size() == 0 however, it equals 38


this.assertEqual([].size(), $H([]).size());

Comments and changes to this ticket

  • Mark Caudill

    Mark Caudill August 26th, 2008 @ 07:40 AM

    • → Tag changed from “constructor hash needs_patch” to “hash object”

    I think this is normal behavior. Hash's should be based on an object, not an array object (as specified in the documentation).

  • tc

    tc August 26th, 2008 @ 07:52 AM

    Ah, you might be right there (regarding the documentation and expected usage of Hash). 1.5 definitely behaved differently when passing in an array. ie. $H([]).size() == 0

    Which was one reason for me thinking it was an error in 1.6

    I just checked 1.6 with the following...

    
    $H(['aoeu']).size()
    

    and it returns 39. Thus it's always converting the entire object. I was previously under the impression that. Passing an empty array and a full array produced different results ... but I was mistaken. ie. I thought $H(['aoeu']).size() == 1 ... but it doesn't it equals 39.

  • Tobie Langel

    Tobie Langel August 26th, 2008 @ 09:45 AM

    • → State changed from “new” to “invalid”

    $H isn't an array to hash converter. The behaviour you are seeing is indeed the expected one. Closing this as invalid.

  • tc

    tc August 27th, 2008 @ 03:08 AM

    doh! Sorry guys. I thought I had a live one cos of the different behaviour in 1.5 and 1.6.

    Thanks again

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Tags