diff --git a/.gitignore b/.gitignore index 0e9d1a0bf7..72b5eaf0c6 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ pylint.txt # IDEs .idea/ .vscode/ +*.swp # Django stuff: *.log diff --git a/misago/markup/md/shortimgs.py b/misago/markup/md/shortimgs.py index 1f63b48f60..31e23f9b07 100644 --- a/misago/markup/md/shortimgs.py +++ b/misago/markup/md/shortimgs.py @@ -2,7 +2,7 @@ from markdown.inlinepatterns import LinkPattern from markdown.util import etree -IMAGES_RE = r"\!(\s?)\((<.*?>|([^\)]*))\)" +IMAGES_RE = r"\!\((<.*?>|([^\)]*))\)" class ShortImagesExtension(markdown.Extension): diff --git a/misago/markup/tests/snapshots/snap_test_short_image_markdown.py b/misago/markup/tests/snapshots/snap_test_short_image_markdown.py index 99bb429cd3..9f64e44cee 100644 --- a/misago/markup/tests/snapshots/snap_test_short_image_markdown.py +++ b/misago/markup/tests/snapshots/snap_test_short_image_markdown.py @@ -8,5 +8,15 @@ snapshots = Snapshot() snapshots[ - "test_short_image_markdown 1" + "test_short_image_markdown[base] 1" ] = '

somewhere.com/image.jpg

' +snapshots["test_short_image_markdown[space-one-word] 1"] = "

! (space)

" +snapshots[ + "test_short_image_markdown[space-multiple-words] 1" +] = "

! (space with other words)

" +snapshots[ + "test_short_image_markdown[text-before-mark] 1" +] = '

Text before exclamation marksomewhere.com/image.jpg

' +snapshots[ + "test_short_image_markdown[text-before-with-space] 1" +] = "

Text before with space in between! (sometext)

" diff --git a/misago/markup/tests/test_short_image_markdown.py b/misago/markup/tests/test_short_image_markdown.py index 22a9c2cd67..9d7e4258b4 100644 --- a/misago/markup/tests/test_short_image_markdown.py +++ b/misago/markup/tests/test_short_image_markdown.py @@ -1,7 +1,23 @@ +import pytest + from ..parser import parse -def test_short_image_markdown(request_mock, user, snapshot): - text = "!(http://somewhere.com/image.jpg)" +@pytest.mark.parametrize( + "text", + [ + pytest.param("!(http://somewhere.com/image.jpg)", id="base"), + pytest.param("! (space)", id="space-one-word"), + pytest.param("! (space with other words)", id="space-multiple-words"), + pytest.param( + "Text before exclamation mark!(http://somewhere.com/image.jpg)", + id="text-before-mark", + ), + pytest.param( + "Text before with space in between! (sometext)", id="text-before-with-space" + ), + ], +) +def test_short_image_markdown(request_mock, user, snapshot, text): result = parse(text, request_mock, user, minify=False) snapshot.assert_match(result["parsed_text"])