From 4d7d10dba5215da5c4a284cbe13e13e085c45d93 Mon Sep 17 00:00:00 2001 From: lookshe Date: Fri, 26 Feb 2016 10:56:11 +0100 Subject: skip FS# not followed by number correctly --- ui-shared.c | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index ea6d18b..2d695a7 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -364,27 +364,30 @@ void cgit_commit_link2(char *name, const char *title, const char *class, { if (checkForIssueLink) { int last_match = 0; + int offset = 0; for (;;) { - const char* sub = strstr(name + last_match, "FS#"); - if (sub != NULL) { - const char* sub = strstr(name + last_match, "FS#"); + const char* sub = strstr(name + last_match + offset, "FS#"); + if (sub != NULL) { int found_pos = (sub - (name + last_match)); - if (found_pos > 0) { - char* left_part = sub_str(name, last_match, last_match + found_pos); - cgit_commit_link3(left_part, title, class, head, rev, path); - free(left_part); - } sub += 3; int numbercount = 0; while (*sub >= '0' && *sub <= '9') { numbercount++; sub++; } + if (!numbercount) { + offset = found_pos + 3; + continue; + } else { + offset = 0; + } + if (found_pos > 0) { + char* left_part = sub_str(name, last_match, last_match + found_pos); + cgit_commit_link3(left_part, title, class, head, rev, path); + free(left_part); + } char* issue_part = sub_str(name, last_match + found_pos, last_match + found_pos + 3 + numbercount); - if (numbercount) - cgit_issue_link(issue_part); - else - cgit_commit_link3(issue_part, title, class, head, rev, path); + cgit_issue_link(issue_part); free(issue_part); last_match += found_pos + 3 + numbercount; } else { @@ -1166,26 +1169,30 @@ extern void cgit_author_link(const char *author, const char *head) extern void cgit_check_text_for_issue_link(const char* text) { int last_match = 0; + int offset = 0; for (;;) { - const char* sub = strstr(text + last_match, "FS#"); - if(sub != NULL) { + const char* sub = strstr(text + last_match + offset, "FS#"); + if(sub != NULL) { int found_pos = (sub - (text + last_match)); - if (found_pos > 0) { - char* left_part = sub_str(text, last_match, last_match + found_pos); - html_txt(left_part); - free(left_part); - } sub += 3; int numbercount = 0; while (*sub >= '0' && *sub <= '9') { numbercount++; sub++; } + if (!numbercount) { + offset = found_pos + 3; + continue; + } else { + offset = 0; + } + if (found_pos > 0) { + char* left_part = sub_str(text, last_match, last_match + found_pos); + html_txt(left_part); + free(left_part); + } char* issue_part = sub_str(text, last_match + found_pos, last_match + found_pos + 3 + numbercount); - if (numbercount) - cgit_issue_link(issue_part); - else - html_txt(issue_part); + cgit_issue_link(issue_part); free(issue_part); last_match += found_pos + 3 + numbercount; } else { -- cgit v1.2.3