ClojureScript

(hash obj-map) inappropriately depends on key order.

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test

Description

Seqing on obj-maps moves in key insertion order, which can lead to different hash values for maps with equal key/value pairs.
This issue is related to CLJS-118, and attached patch fixes it in the same way (i.e., seq in sorted key order).

Commit here

https://github.com/lynaghk/clojurescript/tree/143-hash-obj-map

Activity

Hide
Dave Sann added a comment - - edited

There appears to still be an issue with this in the following scenario:

(ns test
  (:require [cljs.reader :as reader]))

(defn log [x]
  (.log js/console (pr-str x))
  x)

(def data
 {{:start 143  :end 144}  "data" })

(log {:data data})

(doseq [k (keys data)]  
  (let [ks (pr-str k)
        kr (reader/read-string ks)]
    (log  {:k      k 
           :v      (get data k)
           :k-hash (hash k)
           :read-k kr
           :read-k-hash (hash kr)
           :read-v (get data kr)})))

my output:

{:data {{:end 144, :start 143} "data"}}
{:k {:end 144, :start 143},
 :k-hash 40749209, 
 :read-k {:start 143, :end 144}, 
 :read-k-hash -1503612376, 
 :read-v nil, 
 :v "data"}

I have checked my cljs version and the patch has been applied.
can this be confirmed?

Show
Dave Sann added a comment - - edited There appears to still be an issue with this in the following scenario:
(ns test
  (:require [cljs.reader :as reader]))

(defn log [x]
  (.log js/console (pr-str x))
  x)

(def data
 {{:start 143  :end 144}  "data" })

(log {:data data})

(doseq [k (keys data)]  
  (let [ks (pr-str k)
        kr (reader/read-string ks)]
    (log  {:k      k 
           :v      (get data k)
           :k-hash (hash k)
           :read-k kr
           :read-k-hash (hash kr)
           :read-v (get data kr)})))
my output:
{:data {{:end 144, :start 143} "data"}}
{:k {:end 144, :start 143},
 :k-hash 40749209, 
 :read-k {:start 143, :end 144}, 
 :read-k-hash -1503612376, 
 :read-v nil, 
 :v "data"}
I have checked my cljs version and the patch has been applied. can this be confirmed?

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: