Skip to content

Commit 50a0bb1

Browse files
kckernclaude
andcommitted
fix(web): /vbox with a missing or non-numeric verse_id answers like live, not 500
PHP quoted verse_id into SQL and MySQL read a non-numeric value as 0 (leading digits otherwise), so live returned 200 with the box for verse id 0. Node passed NaN to the queries and failed. A missing, empty or "0" verse_id now matches live exactly (the original verse panel shows "No scripture verses found."); a non-numeric one matches except that panel, where live echoes the value through its reference cleaner (the pending cleanReference port). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f638580 commit 50a0bb1

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎apps/web/src/app/controllers/AjaxController.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isEmptyReference } from '../../domain/rules/requestParsing.js';
12
import scriptureLookupService from '../../services/ScriptureLookupService.js';
23
import referenceService from '../../services/ReferenceService.js';
34
import verseboxRepository from '../../data/repositories/VerseboxRepository.js';
@@ -90,7 +91,8 @@ export class AjaxController {
9091
async vbox(req, res) {
9192
try {
9293
const p = params(req);
93-
const verseId = parseInt(str(p.verse_id), 10);
94+
// MySQL read PHP's quoted verse_id by its leading digits, and a non-numeric one as 0.
95+
const verseId = parseInt(str(p.verse_id), 10) || 0;
9496
const ver = baseVersion(str(p.ver) || 'LDS');
9597
const seq = str(p.seq);
9698
const prefs = req.cookies?.sg_user ? await this.repo.findPrefs(req.cookies.sg_mail) : null;
@@ -155,7 +157,8 @@ export class AjaxController {
155157
title: verse?.verse_title || '',
156158
titleShort: verse?.verse_title_short || '',
157159
chapter: chapterSlug(verseId),
158-
text: flattenText(ownText[0]?.text || '').trim(),
160+
// live looked the raw verse_id up as a reference: an empty one is the not-found text
161+
text: isEmptyReference(str(p.verse_id)) ? 'No scripture verses found.' : flattenText(ownText[0]?.text || '').trim(),
159162
},
160163
refs,
161164
refslug: verse ? slugifyRef(rowsReference([metaById.get(verseId)].filter(Boolean), 'book_title')) : '',

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@ describe('/vbox', () => {
137137
const res = await request(app).post('/vbox').type('form').send({ verse_id: '26137', seq: "'><script>" });
138138
expect(res.text).not.toContain('<script>');
139139
});
140+
// PHP put verse_id into SQL as a string, and MySQL read a non-numeric one as 0 (its leading
141+
// digits otherwise), so live answers 200 with the box for verse id 0.
142+
it.each([['/vbox?verse_id=abc', 0], ['/vbox?q=abc', 0], ['/vbox', 0], ['/vbox?verse_id=26137abc', 26137]])('%s looks up verse id %i', async (path, id) => {
143+
const res = await request(app).get(path);
144+
expect(res.status).toBe(200);
145+
expect(repo.findVerse).toHaveBeenCalledWith(id);
146+
});
147+
it('an empty verse_id shows the not-found text as the original verse (live looked up "")', async () => {
148+
for (const path of ['/vbox', '/vbox?verse_id=', '/vbox?verse_id=0']) {
149+
const $ = cheerio.load((await request(app).get(path)).text);
150+
expect($('.refpanel tr.original .gridtext').text()).toBe('No scripture verses found.');
151+
}
152+
});
140153
it('leads with references when the saved preference says so', async () => {
141154
repo.findPrefs.mockResolvedValue({ options: { verpanel: 'ref' } });
142155
const res = await request(app).get('/vbox?verse_id=26137').set('Cookie', 'sg_user=Someone; sg_mail=a@example.com');

0 commit comments

Comments
 (0)