Permalink
Browse files

LineParser: Fix stripping for escaped whitespace

  • Loading branch information...
SanketDG committed Jul 24, 2016
1 parent e442dce commit 7de9aedfeb57680ee82af43b3cd8c24659849c75
Showing with 19 additions and 5 deletions.
  1. +13 −5 coalib/parsing/LineParser.py
  2. +6 −0 tests/parsing/LineParserTest.py
@@ -1,5 +1,7 @@
from coala_utils.string_processing.StringConverter import StringConverter
from coala_utils.string_processing import unescape, convert_to_raw
from coala_utils.string_processing import (unescape, convert_to_raw,
position_is_escaped,
unescaped_rstrip)
class LineParser:
@@ -127,10 +129,16 @@ def __separate_by_first_occurrence(string,
if return_second_part_nonempty and delim_pos == len(string):
return "", string.strip(" \n")
return (
string[:delim_pos].strip(" \n"),
string[delim_pos + (len(used_delim) if strip_delim else 0):].strip(
" \n"))
first_part = string[:delim_pos]
second_part = string[delim_pos + (
len(used_delim) if strip_delim else 0):]
if not position_is_escaped(second_part, len(second_part) - 1):
first_part = unescaped_rstrip(first_part)
second_part = unescaped_rstrip(second_part)
return (first_part.lstrip().rstrip("\n"),
second_part.lstrip().rstrip("\n"))
def __get_section_name(self, line):
for begin, end in self.section_name_surroundings.items():
@@ -25,6 +25,12 @@ def test_section_override(self):
self.check_data_set(r"a.b, \a\.\b\ c=",
output_keys=[("a", "b"), ("", r"\a.\b c")])
def test_escaping(self):
self.check_data_set("hello = world\ # yes here's a space",
output_keys=[('', 'hello')],
output_value='world\\ ',
output_comment="# yes here's a space")
def test_multi_value_parsing(self):
self.check_data_set(
"a, b\\ \\=, section.c= = :()&/ \\\\#heres a comment \n",

0 comments on commit 7de9aed

Please sign in to comment.