Philipp Hörist pushed to branch master at gajim / gajim
Commits:
61852300 by lovetox at 2022-06-15T22:56:06+02:00
fix: Limit max quote recursion
Fixes #10977
- - - - -
1 changed file:
- gajim/common/styling.py
Changes:
=====================================
gajim/common/styling.py
=====================================
@@ -54,6 +54,7 @@
SD = 0
SD_POS = 1
+MAX_QUOTE_LEVEL = 20
@dataclass
@@ -116,6 +117,12 @@ class PlainBlock(Block):
uris: list[BaseUri] = field(default_factory=list)
emojis: list[Emoji] = field(default_factory=list)
+ @classmethod
+ def from_quote_match(cls, match: Match[str]) -> PlainBlock:
+ return cls(start=match.start(),
+ end=match.end(),
+ text=match.group('quote'))
+
@dataclass
class PreBlock(Block):
@@ -187,11 +194,11 @@ def find_byte_index(text: str, index: int):
raise ValueError('index not in string: %s, %s' % (text, index))
-def process(text: Union[str, bytes], nested: bool = False) -> ParsingResult:
+def process(text: Union[str, bytes], level: int = 0) -> ParsingResult:
if isinstance(text, bytes):
text = text.decode()
- blocks = _parse_blocks(text, nested)
+ blocks = _parse_blocks(text, level)
for block in blocks:
if isinstance(block, PlainBlock):
offset = 0
@@ -204,18 +211,18 @@ def process(text: Union[str, bytes], nested: bool =
False) -> ParsingResult:
offset_bytes += len(line.encode())
if isinstance(block, QuoteBlock):
- result = process(block.unquote(), nested=True)
+ result = process(block.unquote(), level=level + 1)
block.blocks = result.blocks
return ParsingResult(text, blocks)
-def _parse_blocks(text: str, nested: bool) -> list[Block]:
+def _parse_blocks(text: str, level: int) -> list[Block]:
blocks: list[Block] = []
text_len = len(text)
last_end_pos = 0
- rx = BLOCK_NESTED_RX if nested else BLOCK_RX
+ rx = BLOCK_NESTED_RX if level > 0 else BLOCK_RX
for match in rx.finditer(text):
if match.start() != last_end_pos:
@@ -228,7 +235,10 @@ def _parse_blocks(text: str, nested: bool) -> list[Block]:
group_dict = match.groupdict()
if group_dict.get('quote') is not None:
- blocks.append(QuoteBlock.from_match(match))
+ if level > MAX_QUOTE_LEVEL:
+ blocks.append(PlainBlock.from_quote_match(match))
+ else:
+ blocks.append(QuoteBlock.from_match(match))
if group_dict.get('pre') is not None:
blocks.append(PreBlock.from_match(match))
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/618523002f1ab6b6088534d7c867a823855e6f12
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/618523002f1ab6b6088534d7c867a823855e6f12
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits