Skip to content

Splitter interprets any @ sign as new block start #488

Closed

Description

@juthilo

Describe the bug
The splitter's methods _move_to_comma_or_closing_curly_bracket and _move_to_closed_bracket each contain a check for unexpected block starts. Unfortunately, this interferes with the parsing of entries that contain the @ sign as raw text.

Reproducing

Version: 2.0.0b7

Code:
This example parse fails because of the @ in the title, raising a BlockAbortedException and adding the block to failed_blocks.

test = bibtexparser.parse_string(
    """
    @inproceedings{DBLP:conf/cikm/EsuliM021,
      author       = {Andrea Esuli and Alejandro Moreo and Fabrizio Sebastiani},
      editor       = {Gao Cong and Maya Ramanath},
      title        = {LeQua @ {CLEF} 2022: {A} Shared Task for Evaluating Quantification Systems},
      booktitle    = {Proceedings of the {CIKM} 2021 Workshops co-located with 30th {ACM}
                      International Conference on Information and Knowledge Management {(CIKM}
                      2021), Gold Coast, Queensland, Australia, November 1-5, 2021},
      series       = {{CEUR} Workshop Proceedings},
      volume       = {3052},
      publisher    = {CEUR-WS.org},
      year         = {2021},
      url          = {https://ceur-ws.org/Vol-3052/abstract4.pdf},
      timestamp    = {Fri, 10 Mar 2023 16:22:33 +0100},
      biburl       = {https://dblp.org/rec/conf/cikm/EsuliM021.bib},
      bibsource    = {dblp computer science bibliography, https://dblp.org}
    }
    """
)
print(test.entries_dict['DBLP:conf/cikm/EsuliM021'])

Bibtex:

@inproceedings{DBLP:conf/cikm/EsuliM021,
      author       = {Andrea Esuli and Alejandro Moreo and Fabrizio Sebastiani},
      editor       = {Gao Cong and Maya Ramanath},
      title        = {LeQua @ {CLEF} 2022: {A} Shared Task for Evaluating Quantification Systems},
      booktitle    = {Proceedings of the {CIKM} 2021 Workshops co-located with 30th {ACM}
                      International Conference on Information and Knowledge Management {(CIKM}
                      2021), Gold Coast, Queensland, Australia, November 1-5, 2021},
      series       = {{CEUR} Workshop Proceedings},
      volume       = {3052},
      publisher    = {CEUR-WS.org},
      year         = {2021},
      url          = {https://ceur-ws.org/Vol-3052/abstract4.pdf},
      timestamp    = {Fri, 10 Mar 2023 16:22:33 +0100},
      biburl       = {https://dblp.org/rec/conf/cikm/EsuliM021.bib},
      bibsource    = {dblp computer science bibliography, https://dblp.org}
}

Workaround
Monkey-patching the two methods by removing the @ check leads to a successful parse.

Remaining Questions (Optional)

  • I would be willing to contribute a PR to fix this issue.
  • This issue is a blocker, I'd be grateful for an early fix.

It says in the code that new blocks are identified by being after a new line. If that assumption is generally safe to make, I could remove the two checks altogether. The only other solution I could think of is replacing the "@" check with a tuple of the most common entry types, e.g. startswith(("@article", "@book", "@proceedings", ...)). Let me know if one of those works and I'll gladly prepare a PR.

Activity

  1. MiWeiss commented on Jan 17, 2026

    @MiWeiss
    Collaborator

    Thanks for reporting this issue and for the detailed analysis!

    This is indeed a regression from #416, where we changed the block-start detection to trigger on @entry{ patterns anywhere (not just at line start) for better error recovery. The downside is that legitimate @ signs in field values (like your @ {CLEF} example) now incorrectly trigger block abortion.

    I've implemented a fix (#515) that should give us the best of both worlds:

    • Error recovery still works when a new block starts at the beginning of a line (after optional whitespace)
    • @ signs mid-line are now treated as content, not block starts

    This means your example parses correctly, while we still recover gracefully from malformed blocks like:

      @article{broken, title={Unclosed field
      @article{valid, title={This one recovers}}
    

    The trade-off is that we won't recover from malformed blocks followed by a new block on the same line (not at line start) — but that's a rare edge case, and most real-world BibTeX files have entries on separate lines anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions