From 153f0d6a7e65235b0ccf09d55ceddddfb4aabe41 Mon Sep 17 00:00:00 2001 From: Adrian <64529218+thegruber@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:29:50 +0000 Subject: [PATCH 1/2] Respond 400 from /api/fetchUrl instead of hanging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A url that isn't a single string (url[]=… or a repeated url param) and an unsuccessful scrape both returned without sending a response. Fixes #338 Co-Authored-By: Claude Opus 5.5 --- src/backend/routes/api/links.ts | 8 +++----- src/test/rest/links.ts | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/test/rest/links.ts diff --git a/src/backend/routes/api/links.ts b/src/backend/routes/api/links.ts index caca5ed4..f0c95369 100644 --- a/src/backend/routes/api/links.ts +++ b/src/backend/routes/api/links.ts @@ -21,20 +21,18 @@ router.get('/fetchUrl', async (req: Request, res: Response) => { success: 0, }; - if (!req.query.url) { + if (!req.query.url || typeof req.query.url !== 'string') { res.status(400).json(response); return; } - if (typeof req.query.url !== 'string') { - return; - } - try { const linkData = (await ogs({ url: req.query.url })).result; if (!linkData.success) { + res.status(400).json(response); + return; } diff --git a/src/test/rest/links.ts b/src/test/rest/links.ts new file mode 100644 index 00000000..08d026ca --- /dev/null +++ b/src/test/rest/links.ts @@ -0,0 +1,24 @@ +import chai from 'chai'; +import chaiHTTP from 'chai-http'; +import server from '../../bin/server.js'; + +const {expect} = chai; +const app = server.app; + +chai.use(chaiHTTP); + +describe('Links REST: ', () => { + it('Responds 400 when url is missing', async () => { + const res = await chai.request(app).get('/api/fetchUrl'); + + expect(res).to.have.status(400); + expect(res.body).to.deep.equal({ success: 0 }); + }); + + it('Responds 400 when url is not a single string', async () => { + const res = await chai.request(app).get('/api/fetchUrl?url[]=https://example.com'); + + expect(res).to.have.status(400); + expect(res.body).to.deep.equal({ success: 0 }); + }); +}); From 21bf7a067fbda2fe277fb6ee6e2560301a28e8cb Mon Sep 17 00:00:00 2001 From: Adrian <64529218+thegruber@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:42:28 +0000 Subject: [PATCH 2/2] Mount the links router directly in its test, bump to 2.3.4 Co-Authored-By: Claude Opus 5.5 --- package.json | 2 +- src/test/rest/links.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 13b688b1..f5702d8b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "codex.docs", "license": "Apache-2.0", - "version": "2.3.3", + "version": "2.3.4", "type": "module", "bin": { "codex.docs": "dist/backend/app.js" diff --git a/src/test/rest/links.ts b/src/test/rest/links.ts index 08d026ca..69afbe7e 100644 --- a/src/test/rest/links.ts +++ b/src/test/rest/links.ts @@ -1,10 +1,12 @@ import chai from 'chai'; import chaiHTTP from 'chai-http'; -import server from '../../bin/server.js'; +import express from 'express'; +import links from '../../backend/routes/api/links.js'; const {expect} = chai; -const app = server.app; +const app = express(); +app.use('/api', links); chai.use(chaiHTTP); describe('Links REST: ', () => {