mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #19090 from overleaf/mj-web-metadata
[web] Ignore commented content when parsing metadata GitOrigin-RevId: 78f9b0d6549e60fca4ba8929beb677341d885655
This commit is contained in:
parent
64d9792fe3
commit
e48e4293a6
2 changed files with 24 additions and 2 deletions
|
@ -84,7 +84,8 @@ module.exports = MetaHandler = {
|
|||
const labelRe = MetaHandler.labelRegex()
|
||||
const packageRe = MetaHandler.usepackageRegex()
|
||||
const reqPackageRe = MetaHandler.ReqPackageRegex()
|
||||
for (const line of Array.from(lines)) {
|
||||
for (const rawLine of Array.from(lines)) {
|
||||
const line = MetaHandler._getNonCommentedContent(rawLine)
|
||||
let labelMatch
|
||||
let clean, messy, packageMatch
|
||||
while ((labelMatch = labelRe.exec(line))) {
|
||||
|
@ -128,4 +129,18 @@ module.exports = MetaHandler = {
|
|||
}
|
||||
return projectMeta
|
||||
},
|
||||
|
||||
/**
|
||||
* Trims comment content from line
|
||||
* @param {string} rawLine
|
||||
* @returns {string}
|
||||
*/
|
||||
_getNonCommentedContent(rawLine) {
|
||||
const commentStart = /(?:^%)|(?:[^\\]%)/
|
||||
const match = rawLine.match(commentStart)
|
||||
if (match) {
|
||||
return rawLine.slice(0, match.index)
|
||||
}
|
||||
return rawLine
|
||||
},
|
||||
}
|
||||
|
|
|
@ -187,7 +187,14 @@ describe('MetaHandler', function () {
|
|||
|
||||
describe('getMetaForDoc', function () {
|
||||
beforeEach(function () {
|
||||
this.fakeLines = ['\\usepackage{abc}', 'one', '\\label{aaa}', 'two']
|
||||
this.fakeLines = [
|
||||
'\\usepackage{abc}',
|
||||
'one',
|
||||
'\\label{aaa}',
|
||||
'two',
|
||||
// bbb should not be in the returned labels
|
||||
'commented label % \\label{bbb}',
|
||||
]
|
||||
this.fakeMeta = { labels: ['aaa'], packages: ['abc'] }
|
||||
this.DocumentUpdaterHandler.flushDocToMongo = sinon
|
||||
.stub()
|
||||
|
|
Loading…
Reference in a new issue