Skip to content

Commit 2aa10c9

Browse files
committed
Added some clarity around validation of characters
1 parent 055f3c8 commit 2aa10c9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

extensions/autolink.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,17 @@ static cmark_node *match(cmark_syntax_extension *ext, cmark_parser *parser,
272272
static bool validate_protocol(char protocol[], uint8_t *data, int rewind) {
273273
size_t len = strlen(protocol);
274274

275+
// Check that the protocol matches
275276
for (int i = 1; i <= len; i++) {
276277
if (data[-rewind - i] != protocol[len - i]) {
277278
return false;
278279
}
279280
}
280281

281-
return !cmark_isalnum(data[-rewind - len - 1]);
282+
char prev_char = data[-rewind - len - 1];
283+
284+
// Make sure the character before the protocol is non-alphanumeric
285+
return !cmark_isalnum(prev_char);
282286
}
283287

284288
static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset, int depth) {

0 commit comments

Comments
 (0)