Skip to content

Commit e769043

Browse files
authored
chore: upgrade @koa/router (#463)
Closes: #458
1 parent d822fa7 commit e769043

File tree

7 files changed

+86
-42
lines changed

7 files changed

+86
-42
lines changed

.ncurc.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
reject:
2-
# https://github.com/koajs/router/issues/202
3-
- '@koa/router'
42
# v3 of ldapjs is a large refactoring followed closely by maintainer abandoning the project
53
# I am concerned it might not be stable enough
64
# Possible alternative more actively maintained is https://github.com/ldapts/ldapts

package-lock.json

Lines changed: 47 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"node": "22.21.1"
4545
},
4646
"dependencies": {
47-
"@koa/router": "^13.1.1",
47+
"@koa/router": "^15.0.0",
4848
"@ladjs/koa-views": "^9.0.0",
4949
"commander": "^14.0.2",
5050
"debug": "^4.4.3",

src/file-drop/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const http = require('http');
66
const path = require('path');
77

8-
const Router = require('@koa/router');
8+
const { Router } = require('@koa/router');
99
const fs = require('fs-extra');
1010
const Koa = require('koa');
1111

src/server/routes/api.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const Router = require('@koa/router');
3+
const { Router } = require('@koa/router');
44

55
const router = new Router({
66
prefix: '/db',
@@ -47,14 +47,12 @@ router.delete(
4747
// Entry rights
4848
router.get('/:dbname/entry/:uuid/_rights/:right', couch.getRights);
4949

50-
// Change the patterns to finish with "*attachment" instead of ":attachment+" when
51-
// @koa/router is updated to v14+
5250
// Attachments
53-
router.get('/:dbname/entry/:uuid/:attachment+', couch.getAttachment);
51+
router.get('/:dbname/entry/:uuid/*attachment', couch.getAttachment);
5452
// Delete attachment slightly different from couchdb api. It does not require _rev in the query parameters.
55-
router.delete('/:dbname/entry/:uuid/:attachment+', couch.deleteAttachment);
53+
router.delete('/:dbname/entry/:uuid/*attachment', couch.deleteAttachment);
5654
router.put(
57-
'/:dbname/entry/:uuid/:attachment+',
55+
'/:dbname/entry/:uuid/*attachment',
5856
util.parseRawBody({ limit: '100mb' }),
5957
couch.saveAttachment,
6058
);

src/server/routes/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const Router = require('@koa/router');
3+
const { Router } = require('@koa/router');
44
const passport = require('koa-passport');
55

66
const router = new Router({

test/api.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,38 @@ describe('rest-api as anonymous (data)', () => {
162162

163163
await request.get('/db/test/entry/B/my%2Battachment.txt').expect(404);
164164
});
165+
166+
test('handle attachment names with unescaped slashes', async () => {
167+
await authenticateAs(request, '[email protected]', '123');
168+
// The attachment name intentionally has an encoded "/" to make sure URLs are
169+
// correctly encoded and decoded by the API.
170+
let res = await request
171+
.put('/db/test/entry/B/my/attachment.txt')
172+
.set('Content-Type', 'text/plain')
173+
.set('Accept', 'application/json')
174+
.send('rest-on-couch!!')
175+
.expect(200);
176+
177+
expect(res.body.id).toBe('B');
178+
179+
// Unescaped
180+
res = await request.get('/db/test/entry/B/my/attachment.txt');
181+
expect(res.text).toBe('rest-on-couch!!');
182+
expect(res.headers['content-type']).toBe('text/plain');
183+
184+
// Escaped
185+
res = await request.get('/db/test/entry/B/my%2Fattachment.txt');
186+
expect(res.text).toBe('rest-on-couch!!');
187+
188+
await authenticateAs(request, '[email protected]', '123');
189+
await request
190+
.delete('/db/test/entry/B/my/attachment.txt')
191+
.send()
192+
.expect(200);
193+
await logout(request);
194+
195+
await request.get('/db/test/entry/B/my/attachment.txt').expect(404);
196+
});
165197
});
166198

167199
describe('basic rest-api as [email protected] (data)', () => {

0 commit comments

Comments
 (0)