From 5186e15c6979a5e9bcfca064bfe085470f31cca5 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 12 Mar 2019 00:04:47 -0400 Subject: [PATCH] Only match URLs on word boundaries; add # Fixes #95 --- ansi2html/converter.py | 2 +- tests/test_ansi2html.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ansi2html/converter.py b/ansi2html/converter.py index 72811a8..b31739e 100644 --- a/ansi2html/converter.py +++ b/ansi2html/converter.py @@ -330,7 +330,7 @@ def __init__( self.url_matcher = re.compile( r"(((((https?|ftps?|gopher|telnet|nntp)://)|" r"(mailto:|news:))(%[0-9A-Fa-f]{2}|[-()_.!~*" - r"\';/?:@&=+$,A-Za-z0-9])+)([).!\';/?:,][\s])?)" + r"\';/?#:@&=+$,A-Za-z0-9])+)([).!\';/?:,][\s])?)" ) self.osc_link_re = re.compile("\033\\]8;;(.*?)\007(.*?)\033\\]8;;\007") diff --git a/tests/test_ansi2html.py b/tests/test_ansi2html.py index 04b5d22..5015cfd 100644 --- a/tests/test_ansi2html.py +++ b/tests/test_ansi2html.py @@ -51,8 +51,8 @@ class TestAnsi2HTML: maxDiff = None def test_linkify(self) -> None: - ansi = "http://threebean.org" - target = 'http://threebean.org' + ansi = "http://threebean.org#foobar" + target = 'http://threebean.org#foobar' html = Ansi2HTMLConverter(linkify=True).convert(ansi) assert target in html