From 61a2360df5076ec5772fc0a72d05e0694ae197e9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 25 Apr 2018 14:33:37 +0530 Subject: [PATCH] hints kitten: Detect bracketed URLs and dont include the closing bracket in the URL. --- kittens/hints/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kittens/hints/main.py b/kittens/hints/main.py index a6aedb37e..4955b2a67 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -158,6 +158,9 @@ def regex_finditer(pat, minimum_match_length, line): yield s, e +closing_bracket_map = {'(': ')', '[': ']', '{': '}', '<': '>'} + + def find_urls(pat, line): for m in pat.finditer(line): s, e = m.span() @@ -168,6 +171,9 @@ def find_urls(pat, line): e -= len(url) - idx while line[e - 1] in '.,?!' and e > 1: # remove trailing punctuation e -= 1 + # Detect a bracketed URL + if s > 0 and e > s + 4 and line[s-1] in '({[<' and line[e-1] == closing_bracket_map[line[s-1]]: + e -= 1 yield s, e