Read the source and its declared rule
This extracted shared-string cell stores index 1 into [Ada, Bo]. Indices are zero-based, so its text is Bo. The original import contract requires an integer index inside the supplied table; the example works on extracted records rather than parsing an XLSX package.
| Record | Input JSON |
|---|---|
| Base input | {"index":1,"shared":["Ada","Bo"]} |
Compare the actual paths
The bad path stores the reference itself as text 1. Correct output stores Bo; losing the shared table prevents resolving the source name.
| Path | Output JSON |
|---|---|
| Misleading path | {"accepted":true,"text":"1"} |
| Corrected path | {"accepted":true,"text":"Bo"} |
import {DatabaseSync} from 'node:sqlite';
import {TextDecoder} from 'node:util';
import {inflateSync} from 'node:zlib';
import {posix} from 'node:path';
import {createHash} from 'node:crypto';
const rows=(db,sql)=>db.prepare(sql).all().map(r=>({...r}));
const failed=(action)=>{try{action();return null;}catch(e){return {code:e.errcode??e.code??e.name};}};
import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
if(!corrected)return {accepted:true,text:String(i.index)};
if(!Number.isInteger(i.index)||i.index<0||i.index>=i.shared.length)return {accepted:false,error:'shared-string-reference'};
return {accepted:true,text:i.shared[i.index]};
};
const cases=[{"label":"misleading base","input":{"index":1,"shared":["Ada","Bo"]},"expected":{"accepted":true,"text":"1"},"corrected":false},{"label":"corrected base","input":{"index":1,"shared":["Ada","Bo"]},"expected":{"accepted":true,"text":"Bo"},"corrected":true},{"label":"first shared string","input":{"index":0,"shared":["Ada","Bo"]},"expected":{"accepted":true,"text":"Ada"},"corrected":true},{"label":"out of bounds reference","input":{"index":2,"shared":["Ada","Bo"]},"expected":{"accepted":false,"error":"shared-string-reference"},"corrected":true}];
for(const test of cases){
const actual=run(test.input,test.corrected);
assert.deepEqual(actual,test.expected,test.label);
console.log(test.label,actual);
}
Check boundaries before the next load
Index 0 resolves Ada. Index 2 is outside this two-entry table and must be held.
| Case | Input JSON | Expected output JSON |
|---|---|---|
| First shared-string position | {"index":0,"shared":["Ada","Bo"]} | {"accepted":true,"text":"Ada"} |
| Reference beyond table | {"index":2,"shared":["Ada","Bo"]} | {"accepted":false,"error":"shared-string-reference"} |
What text belongs to index 1 here?
Show the worked answer
Bo. The value 1 is a position in the supplied shared-string table, not the name.