Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions extensions/autolink.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static cmark_node *match(cmark_syntax_extension *ext, cmark_parser *parser,
// inline was finished in inlines.c.
}

static bool validate_protocol(char protocol[], uint8_t *data, int rewind) {
static bool validate_protocol(char protocol[], uint8_t *data, int rewind, uint8_t* start) {
size_t len = strlen(protocol);

// Check that the protocol matches
Expand All @@ -279,6 +279,9 @@ static bool validate_protocol(char protocol[], uint8_t *data, int rewind) {
}
}

if (start >= data - rewind - len)
return true; // start of text, skip prev_char check

char prev_char = data[-rewind - len - 1];

// Make sure the character before the protocol is non-alphanumeric
Expand Down Expand Up @@ -323,12 +326,12 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
continue;

if (strchr(":", c) != NULL) {
if (validate_protocol("mailto:", data, rewind)) {
if (validate_protocol("mailto:", data, rewind, text->as.literal.data)) {
auto_mailto = false;
continue;
}

if (validate_protocol("xmpp:", data, rewind)) {
if (validate_protocol("xmpp:", data, rewind, text->as.literal.data)) {
auto_mailto = false;
is_xmpp = true;
continue;
Expand Down