diff --git a/dotstrings/parser.py b/dotstrings/parser.py index 5716ba1..998062a 100755 --- a/dotstrings/parser.py +++ b/dotstrings/parser.py @@ -14,7 +14,7 @@ class Patterns: comment = re.compile(r"(\'(?:[^\'\\]|\\[\s\S])*\')|//.*|/\*(?:[^*]|\*(?!/))*\*/", re.MULTILINE) whitespace = re.compile(r"\s*", re.MULTILINE) - entry = re.compile(r'"(.*)"\s*=\s*"(.*)";') + entry = re.compile(r'"([^"]*?)"\s*=\s*"((?:[^";]|"(?!\s*;))*?)";', re.DOTALL) class Scanner: diff --git a/tests/strings_files/string_with_multiline_value.strings b/tests/strings_files/string_with_multiline_value.strings new file mode 100644 index 0000000..6589fb1 --- /dev/null +++ b/tests/strings_files/string_with_multiline_value.strings @@ -0,0 +1,13 @@ +"key-case1" = "value +that +has +newlines"; + +"key-case2" = "Major text in one line and just the closing in next line +"; + +"key-case3" = "A paragraph like text structure + +that goes like this and goes on and on + +and ends here"; \ No newline at end of file diff --git a/tests/test_simple.py b/tests/test_simple.py index 9a7dac2..58709c2 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -88,7 +88,7 @@ def test_strings_format(self): self.assertEqual(entries[0].strings_format(), '/* This is a\n multiline comment */\n"carry" = "breathe";') self.assertEqual(entries[1].strings_format(), '/* This is another\n multiline comment, but for a dupe */\n"condition" = "outgoing";') self.assertEqual(entries[2].strings_format(), '/* precious */\n"condition" = "outgoing";') - + def test_string_with_uneven_whitespace(self): """Test that string with uneven whitespaces work""" string_with_uneven_whitespace_path = os.path.join(self.strings_path, "string_with_uneven_whitespace.strings") @@ -103,3 +103,32 @@ def test_string_with_uneven_whitespace(self): self.assertEqual(entries[2].key, "This is again a key") self.assertEqual(entries[2].value, "This is again a value") + + def test_string_with_multiline_value(self) -> None: + """Test the strings that have values spanning multiple lines""" + + multiline_value_path = os.path.join(self.strings_path, "string_with_multiline_value.strings") + entries = dotstrings.load(multiline_value_path) + self.assertEqual(len(entries), 3) + + self.assertEqual(entries[0].key, "key-case1") + self.assertEqual(entries[0].value, """value +that +has +newlines""") + self.assertEqual(entries[0].value, "value\nthat\nhas\nnewlines") + + self.assertEqual(entries[1].key, "key-case2") + self.assertEqual(entries[1].value, """Major text in one line and just the closing in next line +""") + self.assertEqual(entries[1].value, "Major text in one line and just the closing in next line\n") + + self.assertEqual(entries[2].key, "key-case3") + self.assertEqual(entries[2].value, """A paragraph like text structure + +that goes like this and goes on and on + +and ends here""") + + self.assertEqual( + entries[2].value, "A paragraph like text structure\n\nthat goes like this and goes on and on\n\nand ends here")