From 974c3acd780c88f3d00a0c73132dcc3733fb1427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 1 Jun 2021 18:58:26 +0200 Subject: [PATCH] url-mode: off-by-one error in end-point column of auto-detected URLs When an auto-detected URL ended *on* the right-most column, the URL endpoint was off by one, resulting in the underline in URL mode being one character short. --- CHANGELOG.md | 2 ++ url-mode.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fe9b236..b6305093 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -147,6 +147,8 @@ around (https://codeberg.org/dnkl/foot/issues/552). * Selection incorrectly wrapping rows ending with an explicit newline (https://codeberg.org/dnkl/foot/issues/565). +* Off-by-one error in markup of auto-detected URLs when the URL ends + in the right-most column. ### Security diff --git a/url-mode.c b/url-mode.c index 9473dc14..5f56a2f6 100644 --- a/url-mode.c +++ b/url-mode.c @@ -320,14 +320,16 @@ auto_detected(const struct terminal *term, enum url_action action, break; } - if (c >= term->cols - 1 && row->linebreak) + if (c >= term->cols - 1 && row->linebreak) { + /* + * Endpoint is inclusive, and we’ll be subtracting + * 1 from the column when emitting the URL. + */ + c++; emit_url = true; + } if (emit_url) { - /* Heuristic to remove trailing characters that - * are valid URL characters, but typically not at - * the end of the URL */ - bool done = false; struct coord end = {c, r}; if (--end.col < 0) { @@ -335,6 +337,10 @@ auto_detected(const struct terminal *term, enum url_action action, end.col = term->cols - 1; } + /* Heuristic to remove trailing characters that + * are valid URL characters, but typically not at + * the end of the URL */ + bool done = false; do { switch (url[len - 1]) { case L'.': case L',': case L':': case L';': case L'?':