mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Merge pull request #36949 from overleaf/em-bibtex-crlf-upload-fix
[web] fix bibtex parser dropping fields on CRLF/CR line endings GitOrigin-RevId: 6174bedeed92a014c2d7210afb6f39387e8608a8
This commit is contained in:
@@ -75,7 +75,7 @@ export class BibtexEntryAccumulator {
|
||||
if (type.is(StringLiteral)) {
|
||||
// Strip surrounding quotes/braces and collapse multi-line indentation.
|
||||
let s = getText(node.from + 1, node.to - 1)
|
||||
s = s.replaceAll(/\n\s*/g, ' ')
|
||||
s = s.replaceAll(/[\n\r]\s*/g, ' ')
|
||||
this.fieldValue = this.fieldValue.addString(s)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
@tokens {
|
||||
whiteSpace { $[\t\n ]+ }
|
||||
whiteSpace { $[\t\n\r ]+ }
|
||||
|
||||
// Anything outside of an entry at the top level is a BibTeX free-form comment
|
||||
Junk { ![@ \t\n%] ![@]* }
|
||||
Junk { ![@ \t\n\r%] ![@]* }
|
||||
|
||||
// BibLaTeX supports comments starting with a % and extending to the end of
|
||||
// the line
|
||||
Comment { "%" ![\n]* }
|
||||
Comment { "%" ![\n\r]* }
|
||||
|
||||
// See https://metacpan.org/release/AMBS/Text-BibTeX-0.91/view/btparse/doc/bt_language.pod
|
||||
identifierSymbol { $[!$&*+./:;<>?^`_|] | "[" | "]" | "-" }
|
||||
|
||||
@@ -85,7 +85,7 @@ export default class BibLogParser {
|
||||
}
|
||||
this.text = text.replace(/(\r\n)|\r/g, '\n')
|
||||
this.options = options
|
||||
this.lines = text.split('\n')
|
||||
this.lines = this.text.split('\n')
|
||||
|
||||
// each parser is a pair of [regex, processFunction], where processFunction
|
||||
// describes how to transform the regex mactch into a log entry object.
|
||||
|
||||
@@ -296,6 +296,15 @@ describe('logParser', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('should parse a biber .blg file with CRLF line endings', function () {
|
||||
const log = readLog('biber.blg').replace(/\n/g, '\r\n')
|
||||
const bibParser = new BibLogParser(log, {})
|
||||
const result = bibParser.parse()
|
||||
expect(result.all.length).to.equal(14)
|
||||
expect(result.errors.length).to.equal(1)
|
||||
expect(result.warnings.length).to.equal(2)
|
||||
})
|
||||
|
||||
it('should throw an error when non-biblog passed to BibLogParser', function () {
|
||||
const log = readLog('caption-warnings.log')
|
||||
const bibParser = new BibLogParser(log, {})
|
||||
|
||||
Reference in New Issue
Block a user