From 4518e402c70926bead2014c919d244c8fd9db097 Mon Sep 17 00:00:00 2001 From: Petra Baranski Date: Fri, 28 Mar 2025 03:37:04 +0100 Subject: [PATCH] Fix linkparser line handling with multiple parenthesis --- CHANGELOG.md | 1 + include/maddy/linkparser.h | 2 +- tests/maddy/test_maddy_linkparser.cpp | 16 ++++++++++++++++ tools/format.py | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17ff26b..e65dbfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ maddy uses [semver versioning](https://semver.org/). * ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) Updated google test to v1.16.0. * ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) clang-format * ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) automatic update dependencies ci +* ![**FIXED**](https://img.shields.io/badge/-FIXED-%23090) `(This is a [link](/ABC/some file) (the URL will include this).)` should not put the later parenthesis into the link url. ## version 1.3.0 2023-08-26 diff --git a/include/maddy/linkparser.h b/include/maddy/linkparser.h index d6c72d0..2866a22 100644 --- a/include/maddy/linkparser.h +++ b/include/maddy/linkparser.h @@ -40,7 +40,7 @@ public: */ void Parse(std::string& line) override { - static std::regex re(R"(\[([^\]]*)\]\(([^\]]*)\))"); + static std::regex re(R"(\[([^\]]*)\]\(([^)]*)\))"); static std::string replacement = "$1"; line = std::regex_replace(line, re, replacement); diff --git a/tests/maddy/test_maddy_linkparser.cpp b/tests/maddy/test_maddy_linkparser.cpp index b4adc6d..529c122 100644 --- a/tests/maddy/test_maddy_linkparser.cpp +++ b/tests/maddy/test_maddy_linkparser.cpp @@ -37,6 +37,22 @@ TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithLinks) ASSERT_EQ(expected, text); } +TEST( + MADDY_LINKPARSER, ItReplacesMarkdownProperlyEvenWithMultipleParenthesisInLine +) +{ + std::string text = + "(This is a [link](/ABC/some file) (the URL will include this).)"; + std::string expected = + "(This is a link (the URL will include " + "this).)"; + auto linkParser = std::make_shared(); + + linkParser->Parse(text); + + ASSERT_EQ(expected, text); +} + // ----------------------------------------------------------------------------- class DISABLED_MADDY_LINKPARSER : public ::testing::Test diff --git a/tools/format.py b/tools/format.py index 7ee9403..09bd1f7 100644 --- a/tools/format.py +++ b/tools/format.py @@ -123,7 +123,7 @@ def main(): """ if len(sys.argv) != 2: print( - "Usage: python check_clang_format.py " + "Usage: python format.py " ) sys.exit(1) else: