From c584a77e0e3d5588d1c900a3e78b96d959737129 Mon Sep 17 00:00:00 2001 From: MarkusBodensee Date: Sun, 28 Apr 2024 08:36:40 +0200 Subject: [PATCH] Fix URL enclosed in apostrophes or backtick not working issue Check if URL is enclosed in apostrophes or backtick (grave accent). Only if URL is directly preceded by apostrophe/backtick and URL ends with apostrophe/backtick respectively. Fix #14978, fix #14323, fix #14212, close #15058 --- PowerEditor/src/Notepad_plus.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index c34fee002..ae6752ba9 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3278,6 +3278,18 @@ void scanToUrlEnd(TCHAR *text, int textLen, int start, int* distance) *distance = p - start; } +// removeUnwantedTrailingCharFromEnclosedUrl removes a single unwanted trailing character from a URL if the URL is enclosed by a pair of characters. +void removeUnwantedTrailingCharFromEnclosedUrl(int start, TCHAR const * text, int * length) +{ + // Check if URL is enclosed in apostrophes. + if (start > 0 && text [start - 1] == '\'' && text [start + *length - 1] == '\'') + *length -= 1; + + // Check if URL is enclosed in grave accents. + if (start > 0 && text [start - 1] == '`' && text [start + *length - 1] == '`') + *length -= 1; +} + // removeUnwantedTrailingCharFromUrl removes a single unwanted trailing character from an URL. // It has to be called repeatedly, until it returns false, meaning that all unwanted characters are gone. bool removeUnwantedTrailingCharFromUrl (TCHAR const *text, int* length) @@ -3350,6 +3362,8 @@ bool isUrl(TCHAR * text, int textLen, int start, int* segmentLen) bool r = InternetCrackUrl(& text [start], len, 0, & url); if (r) { + removeUnwantedTrailingCharFromEnclosedUrl(start, & text [0], & len); + while (removeUnwantedTrailingCharFromUrl (& text [start], & len)); *segmentLen = len; return true;