coveralls: 
[![Coverage Status](https://coveralls.io/builds/18570156/badge)](https://coveralls.io/builds/18570156)

Coverage decreased (-0.2%) to 97.43% when pulling **a2a628a32acff1b75da9a10ab0f475c81dc53a4f on omangin:fix/163** into **3344a1aa8e3059a8283aa96c99a68f272d686d9d on sciunto-org:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/18570156/badge)](https://coveralls.io/builds/18570156)

Coverage decreased (-0.2%) to 97.43% when pulling **a2a628a32acff1b75da9a10ab0f475c81dc53a4f on omangin:fix/163** into **3344a1aa8e3059a8283aa96c99a68f272d686d9d on sciunto-org:master**.

diff --git a/bibtexparser/bibtexexpression.py b/bibtexparser/bibtexexpression.py
index ac679e4..e15bb21 100644
--- a/bibtexparser/bibtexexpression.py
+++ b/bibtexparser/bibtexexpression.py
@@ -34,36 +34,35 @@ def add_logger_parse_action(expr, log_func):
 
 # Parse action helpers
 # Helpers for returning values from the parsed tokens. Shaped as pyparsing's
-# parse actions. In pyparsing wording:
-# s, l, t, stand for string, location, token
+# parse actions. See pyparsing documentation for the arguments.
 
-def first_token(s, l, t):
+def first_token(string_, location, token):
     # TODO Handle this case correctly!
-    assert(len(t) == 1)
-    return t[0]
+    assert(len(token) == 1)
+    return token[0]
 
 
-def remove_trailing_newlines(s, l, t):
-    if t[0]:
-        return t[0].rstrip('\n')
+def remove_trailing_newlines(string_, location, token):
+    if token[0]:
+        return token[0].rstrip('\n')
 
 
-def remove_braces(s, l, t):
-    if len(t[0]) < 1:
+def remove_braces(string_, location, token):
+    if len(token[0]) < 1:
         return ''
     else:
-        start = 1 if t[0][0] == '{' else 0
-        end = -1 if t[0][-1] == '}' else None
-        return t[0][start:end]
+        start = 1 if token[0][0] == '{' else 0
+        end = -1 if token[0][-1] == '}' else None
+        return token[0][start:end]
 
 
-def field_to_pair(s, l, t):
+def field_to_pair(string_, location, token):
     """
     Looks for parsed element named 'Field'.
 
     :returns: (name, value).
     """
-    f = t.get('Field')
+    f = token.get('Field')
     return (f.get('FieldName'),
             strip_after_new_lines(f.get('Value')))
 
@@ -149,9 +148,28 @@ class BibtexExpression(object):
         entry_type.setParseAction(first_token)
 
         # Entry key: any character up to a ',' without leading and trailing
-        # spaces.
-        key = pp.SkipTo(',')('Key')  # Exclude @',\#}{~%
-        key.setParseAction(lambda s, l, t: first_token(s, l, t).strip())
+        # spaces. Also exclude spaces and prevent it from being empty.
+        key = pp.SkipTo(',')('Key')  # TODO Maybe also exclude @',\#}{~%
+
+        def citekeyParseAction(string_, location, token):
+            """Parse action for validating citekeys.
+
+            It ensures citekey is not empty and has no space.
+
+            :args: see pyparsing documentation.
+            """
+            key = first_token(string_, location, token).strip()
+            if len(key) < 1:
+                raise self.ParseException(
+                    string_, loc=location, msg="Empty citekeys are not allowed.")
+            for i, c in enumerate(key):
+                if c.isspace():
+                    raise self.ParseException(
+                        string_, loc=(location + i),
+                        msg="Whitespace not allowed in citekeys.")
+            return key
+
+        key.setParseAction(citekeyParseAction)
 
         # Field name: word of letters, digits, dashes and underscores
         field_name = pp.Word(pp.alphanums + '_-().+')('FieldName')

Records with no ID parsed incorrectly
Given the following record:

> @misc{
author = {AMAP},
title = {Summary – The Greenland Ice Sheet in a Changing Climate: Snow, Water, Ice and Permafrost in the Arctic (SWIPA)},
publisher = {Arctic Monitoring and Assessment Programme (AMAP)},
pages = {22 pp.},
year = {2009},
type = {Generic},
}

The parser sets ID as "author = {AMAP" and doesn't recognize the author field.

Changing `re.split(',\s*\n|\n\s*,', record)` to `re.split('(?<={)\s*\n|,\s*\n|\n\s*,', record)` line 239 of bparser.py seems to fix the problem.
diff --git a/bibtexparser/tests/test_bibtexexpression.py b/bibtexparser/tests/test_bibtexexpression.py
index 1306861..1bcab43 100644
--- a/bibtexparser/tests/test_bibtexexpression.py
+++ b/bibtexparser/tests/test_bibtexexpression.py
@@ -58,6 +58,26 @@ class TestBibtexExpression(unittest.TestCase):
     def test_entry_declaration_after_space(self):
         self.expr.entry.parseString('  @journal{key, name = {abcd}}')
 
+    def test_entry_declaration_no_key(self):
+        with self.assertRaises(self.expr.ParseException):
+            self.expr.entry.parseString('@misc{name = {abcd}}')
+
+    def test_entry_declaration_no_key_new_line(self):
+        with self.assertRaises(self.expr.ParseException):
+            self.expr.entry.parseString('@misc{\n name = {abcd}}')
+
+    def test_entry_declaration_no_key_comma(self):
+        with self.assertRaises(self.expr.ParseException):
+            self.expr.entry.parseString('@misc{, \nname = {abcd}}')
+
+    def test_entry_declaration_no_key_keyvalue_without_space(self):
+        with self.assertRaises(self.expr.ParseException):
+            self.expr.entry.parseString('@misc{\nname=aaa}')
+
+    def test_entry_declaration_key_with_whitespace(self):
+        with self.assertRaises(self.expr.ParseException):
+            self.expr.entry.parseString('@misc{ xx yy, \n name = aaa}')
+
     def test_string_declaration_after_space(self):
         self.expr.string_def.parseString('  @string{ name = {abcd}}')
 
diff --git a/bibtexparser/tests/test_bparser.py b/bibtexparser/tests/test_bparser.py
index 479ac34..516411a 100644
--- a/bibtexparser/tests/test_bparser.py
+++ b/bibtexparser/tests/test_bparser.py
@@ -612,6 +612,13 @@ class TestBibtexParserList(unittest.TestCase):
         self.assertEqual(res_dict, expected_dict)
         self.assertEqual(bib.preambles, ["Blah blah"])
 
+    def test_no_citekey_parsed_as_comment(self):
+        bib = BibTexParser('@BOOK{, title = "bla"}')
+        self.assertEqual(bib.entries, [])
+        self.assertEqual(bib.preambles, [])
+        self.assertEqual(bib.strings, {})
+        self.assertEqual(bib.comments, ['@BOOK{, title = "bla"}'])
+
 
 if __name__ == '__main__':
     unittest.main()

pip install -e .
parse_log_pytest
requirements.txt
nose nose-cov pytest
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
-e git+https://github.com/sciunto-org/python-bibtexparser.git@37bd93927d1380f040d391dc132eaf04fbe279af#egg=bibtexparser
cov-core==1.15.0
coverage==7.8.0
exceptiongroup==1.2.2
future==1.0.0
iniconfig==2.1.0
linecache2==1.0.0
nose==1.3.7
nose-cov==1.6
packaging==24.2
pluggy==1.5.0
pyparsing==3.2.3
pytest==8.3.5
six==1.17.0
tomli==2.2.1
traceback2==1.4.0
unittest2==1.1.0

name: python-bibtexparser
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - argparse==1.4.0
      - cov-core==1.15.0
      - coverage==7.8.0
      - exceptiongroup==1.2.2
      - future==1.0.0
      - iniconfig==2.1.0
      - linecache2==1.0.0
      - nose==1.3.7
      - nose-cov==1.6
      - packaging==24.2
      - pluggy==1.5.0
      - pyparsing==3.2.3
      - pytest==8.3.5
      - six==1.17.0
      - tomli==2.2.1
      - traceback2==1.4.0
      - unittest2==1.1.0
prefix: /opt/conda/envs/python-bibtexparser

bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_entry_declaration_key_with_whitespace bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_entry_declaration_no_key_comma bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_no_citekey_parsed_as_comment
bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_braced bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_braced_unicode bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_braced_with_new_line bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_capital_key bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_capital_type bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_declaration_after_space bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_declaration_after_space_and_comment bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_entry_declaration_after_space bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_minimal bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_quoted bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_quoted_with_new_line bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_quoted_with_unicode bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article_annotation bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article_comma_first bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article_cust_latex bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article_cust_order bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article_cust_unicode bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article_missing_coma bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article_no_braces bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article_protection_braces bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article_special_characters bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article_start_bom bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_article_start_with_whitespace bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_book bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_book_cust_latex bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_book_cust_unicode bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_comments_spaces_and_declarations bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_encoding bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_encoding_with_homogenize bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_features bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_features2 bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_field_name_with_dash_underscore bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_nonstandard_ignored bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_nonstandard_not_ignored bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_oneline bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_string_definitions bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_string_is_interpolated bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_string_is_not_interpolated bibtexparser/tests/test_bparser.py::TestBibtexParserList::test_traps
bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_entry_declaration_no_key bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_entry_declaration_no_key_keyvalue_without_space bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_entry_declaration_no_key_new_line bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_preamble_declaration_after_space bibtexparser/tests/test_bibtexexpression.py::TestBibtexExpression::test_string_declaration_after_space
bibtexparser/bibtexexpression.py
bibtexparser/bibtexexpression.py