Skip to content

Commit

Permalink
fix #3; allow for blank lines in input file
Browse files Browse the repository at this point in the history
  • Loading branch information
shapiromatron committed Apr 10, 2018
1 parent aee2923 commit 4bbe5fa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
History
=======

v0.4.3 (2018-04-10)
-------------------
* Allow for blank lines at beginning of input file [fixes #3]


v0.4.2 (2017-05-29)
-------------------
* parser saves unknown tags into an ``unknown_tag`` key in dict
Expand Down
2 changes: 1 addition & 1 deletion RISparser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Parse WOK and Refman's RIS files"""

__version__ = '0.4.2'
__version__ = '0.4.3'

from .config import LIST_TYPE_TAGS, TAG_KEY_MAPPING # noqa
from .parser import * # noqa
2 changes: 1 addition & 1 deletion RISparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def readris(file_, mapping=None, wok=False):
# Corrects for BOM in utf-8 encodings while keeping an 8-bit
# string representation
st = filelines[0]
if (st[0], st[1], st[2]) == ('\xef', '\xbb', '\xbf'):
if len(st) >= 3 and (st[0], st[1], st[2]) == ('\xef', '\xbb', '\xbf'):
filelines[0] = st[3:]

return read(filelines, mapping, wok)
Expand Down
11 changes: 11 additions & 0 deletions tests/example_starting_newlines.ris
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


TY - JOUR
AU - Shannon,Claude E.
PY - 1948/07//
TI - A Mathematical Theory of Communication
JF - Bell System Technical Journal
SP - 379
EP - 423
VL - 27
ER -
6 changes: 6 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,9 @@ def test_parse_multiple_unknown_tags_ris(self):
with open(filepath, 'r') as bibliography_file:
entries = list(readris(bibliography_file))
self.compare([result_entry], entries)

def test_starting_newline(self):
fn = os.path.join(CURRENT_DIR, 'example_starting_newlines.ris')
with open(fn, 'r') as f:
entries = list(readris(f))
assert len(entries) == 1

0 comments on commit 4bbe5fa

Please sign in to comment.