Skip to content

Commit

Permalink
Merge pull request #273 from waldyrious/marker-vs-delimiter
Browse files Browse the repository at this point in the history
Normalize nomenclature: marker row vs. delimiter row
  • Loading branch information
anticomputer authored Jul 20, 2023
2 parents c123e68 + cd27f96 commit 63dd7b7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
40 changes: 20 additions & 20 deletions extensions/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
unsigned char *input, int len) {
cmark_node *table_header;
table_row *header_row = NULL;
table_row *marker_row = NULL;
table_row *delimiter_row = NULL;
node_table_row *ntr;
const char *parent_string;
uint16_t i;
Expand All @@ -319,16 +319,16 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
return parent_container;
}

// Since scan_table_start was successful, we must have a marker row.
marker_row = row_from_string(self, parser,
input + cmark_parser_get_first_nonspace(parser),
len - cmark_parser_get_first_nonspace(parser));
// Since scan_table_start was successful, we must have a delimiter row.
delimiter_row = row_from_string(
self, parser, input + cmark_parser_get_first_nonspace(parser),
len - cmark_parser_get_first_nonspace(parser));
// assert may be optimized out, don't rely on it for security boundaries
if (!marker_row) {
if (!delimiter_row) {
return parent_container;
}
assert(marker_row);

assert(delimiter_row);

cmark_arena_push();

Expand All @@ -338,31 +338,31 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
parent_string = cmark_node_get_string_content(parent_container);
header_row = row_from_string(self, parser, (unsigned char *)parent_string,
(int)strlen(parent_string));
if (!header_row || header_row->n_columns != marker_row->n_columns) {
free_table_row(parser->mem, marker_row);
if (!header_row || header_row->n_columns != delimiter_row->n_columns) {
free_table_row(parser->mem, delimiter_row);
free_table_row(parser->mem, header_row);
cmark_arena_pop();
parent_container->flags |= CMARK_NODE__TABLE_VISITED;
return parent_container;
}

if (cmark_arena_pop()) {
marker_row = row_from_string(
delimiter_row = row_from_string(
self, parser, input + cmark_parser_get_first_nonspace(parser),
len - cmark_parser_get_first_nonspace(parser));
header_row = row_from_string(self, parser, (unsigned char *)parent_string,
(int)strlen(parent_string));
// row_from_string can return NULL, add additional check to ensure n_columns match
if (!marker_row || !header_row || header_row->n_columns != marker_row->n_columns) {
free_table_row(parser->mem, marker_row);
if (!delimiter_row || !header_row || header_row->n_columns != delimiter_row->n_columns) {
free_table_row(parser->mem, delimiter_row);
free_table_row(parser->mem, header_row);
return parent_container;
}
}

if (!cmark_node_set_type(parent_container, CMARK_NODE_TABLE)) {
free_table_row(parser->mem, header_row);
free_table_row(parser->mem, marker_row);
free_table_row(parser->mem, delimiter_row);
return parent_container;
}

Expand All @@ -375,12 +375,12 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
parent_container->as.opaque = parser->mem->calloc(1, sizeof(node_table));
set_n_table_columns(parent_container, header_row->n_columns);

// allocate alignments based on marker_row->n_columns
// since we populate the alignments array based on marker_row->cells
// allocate alignments based on delimiter_row->n_columns
// since we populate the alignments array based on delimiter_row->cells
uint8_t *alignments =
(uint8_t *)parser->mem->calloc(marker_row->n_columns, sizeof(uint8_t));
for (i = 0; i < marker_row->n_columns; ++i) {
node_cell *node = &marker_row->cells[i];
(uint8_t *)parser->mem->calloc(delimiter_row->n_columns, sizeof(uint8_t));
for (i = 0; i < delimiter_row->n_columns; ++i) {
node_cell *node = &delimiter_row->cells[i];
bool left = node->buf->ptr[0] == ':', right = node->buf->ptr[node->buf->size - 1] == ':';

if (left && right)
Expand Down Expand Up @@ -421,7 +421,7 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
(int)strlen((char *)input) - 1 - cmark_parser_get_offset(parser), false);

free_table_row(parser->mem, header_row);
free_table_row(parser->mem, marker_row);
free_table_row(parser->mem, delimiter_row);
return parent_container;
}

Expand Down
2 changes: 1 addition & 1 deletion test/extensions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fff | ggg | hhh | iii | jjj

### Table cell count mismatches

The header and marker row must match.
The header and delimiter row must match.

```````````````````````````````` example
| a | b | c |
Expand Down

0 comments on commit 63dd7b7

Please sign in to comment.