Fix comparing CFIs with different number of !s

Fixes #45
This commit is contained in:
John Factotum
2024-12-21 04:56:43 +08:00
parent 63a5dbf3e3
commit 34b9079a1b
2 changed files with 3 additions and 1 deletions
+1 -1
View File
@@ -167,7 +167,7 @@ export const compare = (a, b) => {
|| compare(collapse(a, true), collapse(b, true)) || compare(collapse(a, true), collapse(b, true))
for (let i = 0; i < Math.max(a.length, b.length); i++) { for (let i = 0; i < Math.max(a.length, b.length); i++) {
const p = a[i], q = b[i] const p = a[i] ?? [], q = b[i] ?? []
const maxIndex = Math.max(p.length, q.length) - 1 const maxIndex = Math.max(p.length, q.length) - 1
for (let i = 0; i <= maxIndex; i++) { for (let i = 0; i <= maxIndex; i++) {
const x = p[i], y = q[i] const x = p[i], y = q[i]
+2
View File
@@ -227,6 +227,8 @@ const XHTML = str => parser.parseFromString(str, 'application/xhtml+xml')
'/6/4!/4/12', '/6/4!/4/12',
-1, -1,
], ],
['/6/4', '/6/4!/2', -1],
['/6/4!/2', '/6/4!/2!/2', -1],
]) { ]) {
const x = CFI.compare(a, b) const x = CFI.compare(a, b)
console.assert(x === c, `compare ${a} and ${b}, expected ${c}, got ${x}`) console.assert(x === c, `compare ${a} and ${b}, expected ${c}, got ${x}`)