Skip to content

Commit 72243ab

Browse files
kckernclaude
andcommitted
fix(web): meta blocks after a cross-book range follow PHP's running book
After a "Multi" block the package names the book again ("…; John 3"), which metaFromRef doubled into "John John 3"; PHP's piece was bare, so live has "John 3". The book is now dropped when the request's piece had none. Bare pieces after a leading cross-book range, which the package drops, become PHP's getBook junk blocks (" 16:1" with no book and verse_ids false, "3: 3:4"), as live returns them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4276c97 commit 72243ab

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎apps/web/src/presentation/legacy/meta.js‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,15 @@ export function metaFromRef(ref) {
7777
if (!normalized) return [];
7878
const blocks = [];
7979
let book = '';
80-
for (const piece of blockTexts(ref, normalized)) {
80+
const texts = blockTexts(ref, normalized);
81+
const inputs = String(ref).split(';');
82+
for (const [k, piece] of texts.entries()) {
8183
let orig = trimChars(piece, ';:');
8284
if (!orig.trim()) continue;
85+
// After a "Multi" block the package names the book again ("…; John 3"); PHP's piece was
86+
// bare (" 3") when the request's was, so it took the running book once
87+
if (blocks.at(-1)?.book === 'Multi' && book && texts.length === inputs.length && !/[a-z]/i.test(inputs[k]) &&
88+
orig.trim().startsWith(`${book} `)) orig = ` ${orig.trim().slice(book.length + 1)}`;
8389
// A range across a book end: cleanReference wrote it without spaces ("Malachi 4:5-Matthew
8490
// 1:2"), and loadMetaFromRef made it one "Multi" block before getBook, keeping the book
8591
const joined = orig.trim().replace(/\s+-\s+/g, '-');
@@ -93,6 +99,16 @@ export function metaFromRef(ref) {
9399
const ids = lookupIds(/[a-z]/i.test(bare) ? bare : `${book} ${bare}`);
94100
blocks.push({ orig, book, verse_ids: ids });
95101
}
102+
// Bare pieces after a leading "Multi" block, which the package drops (no book to read them
103+
// by): PHP's getBook read junk from them (" 16:1" no book, verse_ids false; "3: 3:4")
104+
if (blocks.length === 1 && blocks[0].book === 'Multi' && inputs.length > 1) {
105+
for (const input of inputs.slice(1)) {
106+
if (/[a-z]/i.test(input) || !input.trim()) return blocks;
107+
const cleaned = ` ${input.trim().replace(/(\d+)\.(\d+)/g, '$1:$2')}`;
108+
const junkBook = getBook(cleaned, book);
109+
blocks.push({ orig: junkBook + cleaned, book: junkBook, verse_ids: junkBook ? lookupIds(junkBook + cleaned) : false });
110+
}
111+
}
96112
return blocks;
97113
}
98114

‎apps/web/test/unit/legacyMeta.test.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ describe('metaFromRef (scriptures::loadMetaFromRef)', () => {
3333
]);
3434
});
3535

36+
test('a bare piece after a "Multi" block takes the book before it, without doubling it', () => {
37+
expect(metaFromRef('john.3.16;mal.4.5-matt.1.2;3').map(b => [b.orig, b.book])).toEqual([
38+
['John 3:16', 'John'], ['Malachi 4:5-Matthew 1:2', 'Multi'], ['John 3', 'John'],
39+
]);
40+
});
41+
42+
test('a bare piece after a leading "Multi" block has no book: PHP\'s getBook junk', () => {
43+
expect(metaFromRef('acts.28.31-rom.1.1;16.1')[1]).toEqual({ orig: ' 16:1', book: '', verse_ids: false });
44+
expect(metaFromRef('gen.50.26-ex.1.2;3.4')[1]).toEqual({ orig: '3: 3:4', book: '3:', verse_ids: [] });
45+
});
46+
3647
test('a block after a "Multi" one still repeats its own book, as PHP did', () => {
3748
expect(metaFromRef('mal.4.6-matt.1.1;john.3.16').map(b => [b.orig, b.book])).toEqual([
3849
['Malachi 4:6-Matthew 1:1', 'Multi'], ['John John 3:16', 'John'],

0 commit comments

Comments
 (0)