mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
[docstore] fix evaluating dollar based references (#31792)
Co-authored-by: Brian Gough <brian.gough@overleaf.com> GitOrigin-RevId: 8ffc1d1f930d0ac3c68cd59d8412932fea4229cd
This commit is contained in:
@@ -100,7 +100,8 @@ function convertUpdateToPipeline(update) {
|
||||
// $unset uses a different schema in a pipeline
|
||||
pipeline.push({ [operation]: field })
|
||||
} else {
|
||||
pipeline.push({ [operation]: { [field]: value } })
|
||||
// Avoid evaluating '$foo' strings
|
||||
pipeline.push({ [operation]: { [field]: { $literal: value } } })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,9 +56,9 @@ describe('MongoManager', () => {
|
||||
}
|
||||
const pipeline = ctx.MongoManager.convertUpdateToPipeline(update)
|
||||
expect(pipeline).to.deep.equal([
|
||||
{ $set: { lines: ['foo', 'bar'] } },
|
||||
{ $set: { ranges: { comments: [] } } },
|
||||
{ $set: { rev: 42 } },
|
||||
{ $set: { lines: { $literal: ['foo', 'bar'] } } },
|
||||
{ $set: { ranges: { $literal: { comments: [] } } } },
|
||||
{ $set: { rev: { $literal: 42 } } },
|
||||
{ $unset: 'inS3' },
|
||||
])
|
||||
})
|
||||
@@ -243,8 +243,8 @@ describe('MongoManager', () => {
|
||||
project_id: new ObjectId(ctx.projectId),
|
||||
rev: ctx.oldRev,
|
||||
})
|
||||
assert.equal(args[1][0].$set.lines, ctx.lines)
|
||||
assert.equal(args[1][1].$set.rev, ctx.oldRev + 1)
|
||||
assert.equal(args[1][0].$set.lines.$literal, ctx.lines)
|
||||
assert.equal(args[1][1].$set.rev.$literal, ctx.oldRev + 1)
|
||||
})
|
||||
|
||||
it('should fallback on mismatch', async ctx => {
|
||||
@@ -418,16 +418,8 @@ describe('MongoManager', () => {
|
||||
rev: ctx.archivedDoc.rev,
|
||||
},
|
||||
[
|
||||
{
|
||||
$set: {
|
||||
lines: ctx.archivedDoc.lines,
|
||||
},
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
ranges: ctx.archivedDoc.ranges,
|
||||
},
|
||||
},
|
||||
{ $set: { lines: { $literal: ctx.archivedDoc.lines } } },
|
||||
{ $set: { ranges: { $literal: ctx.archivedDoc.ranges } } },
|
||||
{ $unset: 'inS3' },
|
||||
]
|
||||
)
|
||||
@@ -482,14 +474,12 @@ describe('MongoManager', () => {
|
||||
[
|
||||
{
|
||||
$set: {
|
||||
lines: ctx.archivedDoc.lines,
|
||||
},
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
ranges: {},
|
||||
lines: {
|
||||
$literal: ctx.archivedDoc.lines,
|
||||
},
|
||||
},
|
||||
},
|
||||
{ $set: { ranges: { $literal: {} } } },
|
||||
{ $unset: 'inS3' },
|
||||
]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user