Repository: rafalp/Misago

Issue:
BBCode block parser doesn't parse nested rules
Repro:

```
[quote]
[spoiler]
Hidden text
[/spoiler]
[/quote]

[spoiler]
[quote]
Hidden quote
[/quote]
[/spoiler]
[quote]
[spoiler]
Hidden text
[/spoiler]
[/quote]

[spoiler]
[quote]
[code]
secret quoted code
[/code]
[/quote]
[/spoiler]
```

Discussion:

Solution patch:
diff --git a/misago/parser/bbcode.py b/misago/parser/bbcode.py
index 4eb92941a..b8249c1ff 100644
--- a/misago/parser/bbcode.py
+++ b/misago/parser/bbcode.py
@@ -251,7 +251,7 @@ class BBCodeBlockRule:
         old_line_max = state.lineMax
         old_parent = state.parentType
 
-        state.lineMax = startLine
+        state.lineMax = endLine
         state.parentType = self.name
 
         state.level += 1


Test patch:
diff --git a/misago/parser/tests/test_bbcode_block_rule.py b/misago/parser/tests/test_bbcode_block_rule.py
index 4cf2d489a..07875c2f7 100644
--- a/misago/parser/tests/test_bbcode_block_rule.py
+++ b/misago/parser/tests/test_bbcode_block_rule.py
@@ -71,6 +71,66 @@ def test_bbcode_block_rule_parses_single_line_block_in_multiline_block(parse_to_
     )
 
 
+def test_bbcode_block_rule_parses_multiline_block_with_nested_multiline_block(
+    parse_to_html,
+):
+    html = parse_to_html("[quote]\n[quote]\nnested\n[/quote]\n[/quote]")
+    assert html == (
+        "<misago-quote>"
+        "\n<misago-quote>"
+        "\n<p>nested</p>"
+        "\n</misago-quote>"
+        "\n</misago-quote>"
+    )
+
+
+def test_bbcode_block_rule_parses_multiline_block_with_nested_multiline_block_of_other_type(
+    parse_to_html,
+):
+    html = parse_to_html("[quote]\n[spoiler]\nnested\n[/spoiler]\n[/quote]")
+    assert html == (
+        "<misago-quote>"
+        "\n<misago-spoiler>"
+        "\n<p>nested</p>"
+        "\n</misago-spoiler>"
+        "\n</misago-quote>"
+    )
+
+
+def test_bbcode_block_rule_parses_multiline_block_with_nested_multiline_block_between_paragraphs(
+    parse_to_html,
+):
+    html = parse_to_html(
+        "[quote]\nparagraph1\n[quote]\nnested\n[/quote]\nparagraph2\n[/quote]"
+    )
+    assert html == (
+        "<misago-quote>"
+        "\n<p>paragraph1</p>"
+        "\n<misago-quote>"
+        "\n<p>nested</p>"
+        "\n</misago-quote>"
+        "\n<p>paragraph2</p>"
+        "\n</misago-quote>"
+    )
+
+
+def test_bbcode_block_rule_parses_multiline_block_with_nested_multiline_block_of_other_type_between_paragraphs(
+    parse_to_html,
+):
+    html = parse_to_html(
+        "[quote]\nparagraph1\n[spoiler]\nnested\n[/spoiler]\nparagraph2\n[/quote]"
+    )
+    assert html == (
+        "<misago-quote>"
+        "\n<p>paragraph1</p>"
+        "\n<misago-spoiler>"
+        "\n<p>nested</p>"
+        "\n</misago-spoiler>"
+        "\n<p>paragraph2</p>"
+        "\n</misago-quote>"
+    )
+
+
 def test_bbcode_block_rule_matches_closest_multiline_block_open_close_pair(
     parse_to_html,
 ):