From ec98221d1caae0e984e954eb9f20c92d58d34114 Mon Sep 17 00:00:00 2001 From: Fabien Benureau Date: Sat, 26 Dec 2015 17:20:05 +0100 Subject: [PATCH] Sanitize one-liner strings Fixes #26 --- pubs/pretty.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pubs/pretty.py b/pubs/pretty.py index 0859b61..e39de79 100644 --- a/pubs/pretty.py +++ b/pubs/pretty.py @@ -1,9 +1,16 @@ # display formatting +import re + from . import color from .bibstruct import TYPE_KEY +CHARS = re.compile('[{}\n\t\r]') + +def sanitize(s): + return CHARS.sub('', s) + # should be adaptated to bibtexparser dicts def person_repr(p): raise NotImplementedError @@ -32,13 +39,13 @@ def bib_oneliner(bibdata): elif bibdata[TYPE_KEY] == 'inproceedings': journal = ' ' + bibdata.get('booktitle', '') - return u'{authors} \"{title}\"{journal}{year}'.format( + return sanitize(u'{authors} \"{title}\"{journal}{year}'.format( authors=color.dye_out(authors, 'author'), title=color.dye_out(bibdata.get('title', ''), 'title'), journal=color.dye_out(journal, 'publisher'), year=' ({})'.format(color.dye_out(bibdata['year'], 'year')) if 'year' in bibdata else '' - ) + )) def bib_desc(bib_data):