Bug 247613

Summary: IBDIndex keyPath array with a single entry yielding incorrect key
Product: WebKit Reporter: Ivan Artemiev <ivaartem>
Component: Website StorageAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: cdumez, dima, sihui_liu, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 16   
Hardware: All   
OS: All   

Description Ivan Artemiev 2022-11-08 05:35:22 PST
WPT: https://wpt.live/IndexedDB/idbindex_keyPath.any.html

Steps to reproduce:

const store = db.createObjectStore("store")
store.createIndex("byIdArrayKey", ["id"], { multiEntry: false }))

store.put({
  id: 1,
  title: "hello"
})

Expected behavior:
The index key that gets extracted from the record value should be [1] (array with a single subkey)

Actual results:
On WebKit this yield a scalar key with value 1 (number)
Confirmed on Safari 16 on macOS and iOS and Safari Tech Preview Release 156 (Safari 16.4, WebKit 17615.1.8.5)

An array keyPath should always produce an array key (https://www.w3.org/TR/IndexedDB/#evaluate-a-key-path-on-a-value)

Works as expected on V8 and SpiderMonkey
Note: single entry array keyPaths work as expected with IDBObjectStore on WebKit. The unexpected behavior is only observed with IDBIndex keyPaths.
Comment 1 Radar WebKit Bug Importer 2022-11-15 05:36:15 PST
<rdar://problem/102364019>
Comment 2 Dima Goltsman 2023-05-22 04:14:22 PDT
will this ever be fixed? thats a huge flaw!
Comment 3 Sihui Liu 2023-05-24 08:46:56 PDT

*** This bug has been marked as a duplicate of bug 257238 ***
Comment 4 Chris Dumez 2023-05-24 08:58:21 PDT
Good job adding a web-platform-test Ivan :) This is how I became aware of this issue and decided to fix it in https://github.com/WebKit/WebKit/pull/14269.
Comment 5 Ivan Artemiev 2023-05-25 08:44:44 PDT
Awesome! Thanks for fixing the bug, Chris.