From 6e6564649b6d727e98a4df304d1a6022e0df50b1 Mon Sep 17 00:00:00 2001 From: Goury Date: Sat, 19 Aug 2023 21:43:32 +0300 Subject: [PATCH] fixed string index out of range exception in quotation marks detector/remover --- precise_bbcode/bbcode/defaults/tag.py | 2 +- tests/unit/test_parser.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/precise_bbcode/bbcode/defaults/tag.py b/precise_bbcode/bbcode/defaults/tag.py index ca202c7..ce5e052 100644 --- a/precise_bbcode/bbcode/defaults/tag.py +++ b/precise_bbcode/bbcode/defaults/tag.py @@ -105,7 +105,7 @@ class Options: def render(self, value, option=None, parent=None): href = option if option else value - if href[0] == href[-1] and href[0] in ('"', '\'') and len(href) > 2: + if len(href) > 2 and href[0] == href[-1] and href[0] in ('"', '\''): # URLs can be encapsulated in quotes (either single or double) that aren't part of the # URL. If that's the case, strip them out. href = href[1:-1] diff --git a/tests/unit/test_parser.py b/tests/unit/test_parser.py index c9fd2ac..8d5706e 100644 --- a/tests/unit/test_parser.py +++ b/tests/unit/test_parser.py @@ -116,6 +116,8 @@ class TestParser(object): ('[color=some words]test[/color]', '[color=some words]test[/color]'), # Unknown BBCodes ('[unknown][hello][/unknown]', '[unknown][hello][/unknown]'), + ('[url]"[url]', '[url]"[url]'), + ('[url="]wow, that is very short[url]', '[url="]wow, that is very short[url]'), ) CUSTOM_TAGS_RENDERING_TESTS = {