Fix linkparser line handling with multiple parenthesis

This commit is contained in:
Petra Baranski
2025-03-28 03:37:04 +01:00
committed by GitHub
parent a5b18310a8
commit 4518e402c7
4 changed files with 19 additions and 2 deletions

View File

@@ -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

View File

@@ -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 = "<a href=\"$2\">$1</a>";
line = std::regex_replace(line, re, replacement);

View File

@@ -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 <a href=\"/ABC/some file\">link</a> (the URL will include "
"this).)";
auto linkParser = std::make_shared<maddy::LinkParser>();
linkParser->Parse(text);
ASSERT_EQ(expected, text);
}
// -----------------------------------------------------------------------------
class DISABLED_MADDY_LINKPARSER : public ::testing::Test

View File

@@ -123,7 +123,7 @@ def main():
"""
if len(sys.argv) != 2:
print(
"Usage: python check_clang_format.py <dry_run|format>"
"Usage: python format.py <dry_run|format>"
)
sys.exit(1)
else: