Skip to content

Commit

Permalink
allow transparent backslash escaping in title, fixes #143
Browse files Browse the repository at this point in the history
  • Loading branch information
posativ committed Mar 18, 2013
1 parent 8728ceb commit 20d7df9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions acrylamid/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,16 @@ class Entry(ContentMixin, MetadataMixin, FileReader):
def unsafe(string):
"""Try to remove YAML string escape characters safely from `string`.
---
title: "AttributeError: queryMethodId" when creating an object
---
Title: "AttributeError: get\_id" when creating an object
should retain the quotations around AttributeError."""
Should retain the quotations around AttributeError. Single backslashes
are removed if not preceded by another backslash."""

if len(string) < 2:
return string

string = re.sub(r'\\\\', r'\\', re.sub(r'([^\\]|^)\\([^\\])', r'\1\2', string))

for char in "'", '"':
if string == 2*char:
return ''
Expand Down
8 changes: 8 additions & 0 deletions acrylamid/specs/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ def quotes():
assert distinguish("\"'bout \" and '\"") == "'bout \" and '"


@tt.test
def backslash():

assert distinguish('\\_bar') == '_bar'
assert distinguish('foo\\_') == 'foo_'
assert distinguish('foo\\\\bar') == 'foo\\bar'


@tt.test
def ignore():

Expand Down

0 comments on commit 20d7df9

Please sign in to comment.