aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2025-04-13 06:26:20 +0000
committerDaniel Eklöf <daniel@ekloef.se>2025-04-13 06:28:13 +0000
commitb93d2f042c378e9a2a6d0882c79331492d5dee09 (patch)
tree3edc446e2d75cf510c8d375f8e942a6073c58148
parentchangelog: move vmod support in config from "changed" to "added" (diff)
url-mode: fix double-width characters not being handled correctly
When a regex matches a string containing double-width characters, the CELL_SPACER values were included in the URL string. This meant the final URL (either launched, or copied) weren't handled correctly, as invalid UTF-8 sequences were inserted in the middle of the string. Closes #2027
-rw-r--r--CHANGELOG.md3
-rw-r--r--url-mode.c8
2 files changed, 9 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c2f18c5f..e9f82999 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -106,9 +106,12 @@
* Build failure (`srgb.h` not found) when doing a parallel build.
* Regression: reflowing (changing the window size) removing empty
lines ([#2011][2011]).
+* `url/regex-copy` not handling double-width characters correctly
+ ([#2027][2027]).
[2000]: https://codeberg.org/dnkl/foot/issues/2000
[2011]: https://codeberg.org/dnkl/foot/issues/2011
+[2027]: https://codeberg.org/dnkl/foot/issues/2027
### Security
diff --git a/url-mode.c b/url-mode.c
index ed260597..d0f7fc53 100644
--- a/url-mode.c
+++ b/url-mode.c
@@ -347,6 +347,9 @@ regex_detected(const struct terminal *term, enum url_action action,
wc_count = composed->count;
}
+ else if (wc[0] >= CELL_SPACER)
+ continue;
+
/* Convert wide character to utf8 */
for (size_t i = 0; i < wc_count; i++) {
char buf[16];
@@ -355,6 +358,7 @@ regex_detected(const struct terminal *term, enum url_action action,
if (char_len == (size_t)-1)
continue;
+
for (size_t j = 0; j < char_len; j++) {
const size_t requires_size = vline->len + char_len;
@@ -411,9 +415,9 @@ regex_detected(const struct terminal *term, enum url_action action,
const size_t end = start + mlen;
LOG_DBG(
- "regex match at row %d: %.*srow/col = %dx%d",
+ "regex match at row %d: %.*s (%zu bytes), row/col = %dx%d",
matches[1].rm_so, (int)mlen, &search_string[matches[1].rm_so],
- v->map[start].row, v->map[start].col);
+ mlen, v->map[start].row, v->map[start].col);
tll_push_back(
*urls,