Repository: sciunto-org/python-bibtexparser
Pull request #148 (2016-10-20 17:38:45)

accept extra characters
This patch accept string macros with hyphen and colon:

@string{pub-ieee-std = {IEEE}}
@string{pub-ieee-std:adr = {New York, NY, USA}}

and accept entry field names with period:

Dc.Date = {2004-01},


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

Coverage remained the same at 95.729% when pulling **d3155e55b8cbd7e0c41c15bc24b0a5c9c8917fe2 on noahdesu:accept-fixes** into **87e72d4ceeb83603efe7df4fdcd2ee531eb33680 on sciunto-org:master**.

sciunto: Thank you very much @noahdesu ! Would you like to modify an existing test to reflect these changes?
Phyks: @noahdesu any news on this? Thanks!

Patch:
diff --git a/bibtexparser/bibtexexpression.py b/bibtexparser/bibtexexpression.py
index 881c799..c7b0c83 100644
--- a/bibtexparser/bibtexexpression.py
+++ b/bibtexparser/bibtexexpression.py
@@ -103,7 +103,7 @@ class BibtexExpression(object):
         comment_line_start = pp.CaselessKeyword('@comment')
 
         # String names
-        string_name = pp.Word(pp.alphanums + '_')('StringName')
+        string_name = pp.Word(pp.alphanums + '_-:')('StringName')
         self.set_string_name_parse_action(lambda s, l, t: None)
         string_name.addParseAction(self._string_name_parse_action)
 
@@ -154,7 +154,7 @@ class BibtexExpression(object):
         key.setParseAction(lambda s, l, t: first_token(s, l, t).strip())
 
         # Field name: word of letters, digits, dashes and underscores
-        field_name = pp.Word(pp.alphanums + '_-()')('FieldName')
+        field_name = pp.Word(pp.alphanums + '_-().')('FieldName')
         field_name.setParseAction(first_token)
 
         # Field: field_name = value


Test patch:
diff --git a/bibtexparser/tests/data/fieldname.bib b/bibtexparser/tests/data/fieldname.bib
new file mode 100644
index 0000000..d6a9bf0
--- /dev/null
+++ b/bibtexparser/tests/data/fieldname.bib
@@ -0,0 +1,3 @@
+@BOOK{Bird1987,
+  Dc.Date = {2004-01},
+}
diff --git a/bibtexparser/tests/test_bibtex_strings.py b/bibtexparser/tests/test_bibtex_strings.py
index 3a70ab4..4ca5e3a 100644
--- a/bibtexparser/tests/test_bibtex_strings.py
+++ b/bibtexparser/tests/test_bibtex_strings.py
@@ -49,6 +49,15 @@ class TestStringParse(unittest.TestCase):
                      }]
         self.assertEqual(res, expected)
 
+    def test_string_parse_accept_chars(self):
+        bibtex_str = '@string{pub-ieee-std = {IEEE}}\n\n@string{pub-ieee-std:adr = {New York, NY, USA}}'
+        bib_database = bibtexparser.loads(bibtex_str)
+        self.assertEqual(len(bib_database.strings), 2)
+        expected = OrderedDict()
+        expected['pub-ieee-std'] = 'IEEE'
+        expected['pub-ieee-std:adr'] = 'New York, NY, USA'
+        self.assertEqual(bib_database.strings, expected)
+
 
 class TestStringWrite(unittest.TestCase):
 
diff --git a/bibtexparser/tests/test_bibtexparser.py b/bibtexparser/tests/test_bibtexparser.py
index fafda30..041f0e5 100644
--- a/bibtexparser/tests/test_bibtexparser.py
+++ b/bibtexparser/tests/test_bibtexparser.py
@@ -14,7 +14,7 @@ class TestBibtexParserParserMethods(unittest.TestCase):
                          'ID': 'Bird1987',
                          'volume': '1',
                          'title': 'Dynamics of Polymeric Liquid',
-                         'author': 'Bird, R.B. and Armstrong, R.C. and Hassager, O.'
+                         'author': 'Bird, R.B. and Armstrong, R.C. and Hassager, O.',
                         }]
 
     def test_parse_immediately(self):
@@ -93,6 +93,18 @@ class TestBibtexparserWriteMethods(unittest.TestCase):
 
         self.assertEqual(bibtex_out_str, self.expected)
 
+class TestBibtexparserFieldNames(unittest.TestCase):
+    input_file_path = 'bibtexparser/tests/data/fieldname.bib'
+    entries_expected = [{'ENTRYTYPE': 'book',
+                         'ID': 'Bird1987',
+                         'dc.date': '2004-01'
+                        }]
+
+    def test_parse_immediately(self):
+        with open(self.input_file_path) as bibtex_file:
+            bibtex_str = bibtex_file.read()
+        bibtex_database = BibTexParser(bibtex_str)
+        self.assertEqual(bibtex_database.entries, self.entries_expected)
 
 if __name__ == '__main__':
     unittest.main()