String sort crashes when language is not "english"
cnrdh opened this issue · comments
Describe the bug
stringSort
sends language (eg. "norwegian") instead of locale (eg. "no") to localeCompare, yielding
error: Uncaught (in promise) RangeError: Incorrect locale information provided
at String.localeCompare (<anonymous>)
at stringSort (file:///home/che/.cache/deno/npm/registry.npmjs.org/@orama/orama/2.0.3/dist/components/sorter.js:99:21)
To Reproduce
t.test('on intl language', async (t) => {
const db = await create({
schema: {
string: 'string'
},
language: 'norwegian'
})
const [id1, id2, id3, id4, id5, id6] = await insertMultiple(db, [
{ string: 'å' },
{ string: 'a' },
{ string: 'ø' },
{ string: 'o' },
{ string: 'æ' },
{}
])
t.test('should short using locale - asc', async (t) => {
const result = await search(db, {
sortBy: {
property: 'string'
}
})
t.strictSame(
result.hits.map((d) => d.id),
[id2, id4, id5, id3, id1, id6]
)
t.end()
})
t.end()
})
Expected behavior
Expected properly locale-sorted array
Environment Info
Orama: 2.0.3
Affected areas
Search
Additional context
Chromium
const items = ["a","å","ø","z","æ","o"];
items.sort((a, b) => a.localeCompare(b, "no"));
(6) ['a', 'o', 'z', 'æ', 'ø', 'å']
const items = ["a","å","ø","z","æ","o"];
items.sort((a, b) => a.localeCompare(b, "norwegian"));
VM96:2 Uncaught RangeError: Incorrect locale information provided
at String.localeCompare (<anonymous>)
at <anonymous>:2:24
at Array.sort (<anonymous>)
at <anonymous>:2:7