mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Merge pull request #36860 from overleaf/bg-allow-integer-in-sync-requests
Allow integer values for h and v parameters in proxySyncPdf GitOrigin-RevId: 66f303a5940f6976dcfe27ebf90da8a9ec24e98a
This commit is contained in:
@@ -392,8 +392,8 @@ const proxySyncPdfSchema = z.object({
|
||||
}),
|
||||
query: z.object({
|
||||
page: z.string().regex(/^\d+$/),
|
||||
h: z.string().regex(/^-?\d+\.\d+$/),
|
||||
v: z.string().regex(/^-?\d+\.\d+$/),
|
||||
h: z.string().regex(/^-?\d+(\.\d+)?$/),
|
||||
v: z.string().regex(/^-?\d+(\.\d+)?$/),
|
||||
...syncTeXBaseQuery,
|
||||
}),
|
||||
})
|
||||
@@ -835,10 +835,10 @@ const _CompileController = {
|
||||
if (!page?.match(/^\d+$/)) {
|
||||
throw new Error('invalid page parameter')
|
||||
}
|
||||
if (!h?.match(/^-?\d+\.\d+$/)) {
|
||||
if (!h?.match(/^-?\d+(\.\d+)?$/)) {
|
||||
throw new Error('invalid h parameter')
|
||||
}
|
||||
if (!v?.match(/^-?\d+\.\d+$/)) {
|
||||
if (!v?.match(/^-?\d+(\.\d+)?$/)) {
|
||||
throw new Error('invalid v parameter')
|
||||
}
|
||||
await _syncTeX(
|
||||
|
||||
@@ -1196,6 +1196,57 @@ describe('CompileController', function () {
|
||||
ctx.CompileManager.promises.syncTeX.should.have.been.calledOnce
|
||||
})
|
||||
|
||||
it('should accept integer h and v values with no fractional part', async function (ctx) {
|
||||
ctx.req.query.h = '5'
|
||||
ctx.req.query.v = '-5'
|
||||
ctx.next = sinon.stub()
|
||||
await ctx.CompileController.proxySyncPdf(ctx.req, ctx.res, ctx.next)
|
||||
ctx.next.should.not.have.been.called
|
||||
ctx.CompileManager.promises.syncTeX.should.have.been.calledWith(
|
||||
ctx.projectId,
|
||||
ctx.user_id,
|
||||
sinon.match({
|
||||
validatedOptions: sinon.match({ h: '5', v: '-5' }),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('should reject a non-numeric h value', async function (ctx) {
|
||||
ctx.req.query.h = 'not-a-number'
|
||||
ctx.next = sinon.stub()
|
||||
await ctx.CompileController.proxySyncPdf(ctx.req, ctx.res, ctx.next)
|
||||
ctx.next.should.have.been.calledWithMatch({
|
||||
name: 'InvalidRequestError',
|
||||
zodError: asZodError({
|
||||
origin: 'string',
|
||||
code: 'invalid_format',
|
||||
format: 'regex',
|
||||
pattern: '/^-?\\d+(\\.\\d+)?$/',
|
||||
path: ['query', 'h'],
|
||||
message: 'Invalid string: must match pattern /^-?\\d+(\\.\\d+)?$/',
|
||||
}),
|
||||
})
|
||||
ctx.CompileManager.promises.syncTeX.should.have.been.calledOnce
|
||||
})
|
||||
|
||||
it('should reject a non-numeric v value', async function (ctx) {
|
||||
ctx.req.query.v = 'not-a-number'
|
||||
ctx.next = sinon.stub()
|
||||
await ctx.CompileController.proxySyncPdf(ctx.req, ctx.res, ctx.next)
|
||||
ctx.next.should.have.been.calledWithMatch({
|
||||
name: 'InvalidRequestError',
|
||||
zodError: asZodError({
|
||||
origin: 'string',
|
||||
code: 'invalid_format',
|
||||
format: 'regex',
|
||||
pattern: '/^-?\\d+(\\.\\d+)?$/',
|
||||
path: ['query', 'v'],
|
||||
message: 'Invalid string: must match pattern /^-?\\d+(\\.\\d+)?$/',
|
||||
}),
|
||||
})
|
||||
ctx.CompileManager.promises.syncTeX.should.have.been.calledOnce
|
||||
})
|
||||
|
||||
describe('when the schema is in log-only mode', function () {
|
||||
beforeEach(function () {
|
||||
setReqValidationModeForTests('log')
|
||||
|
||||
Reference in New Issue
Block a user