Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cell_index is not initialized when a table cell is created using cmark_node_new_with_ext() #360

Open
steffen-kiess opened this issue Mar 22, 2024 · 0 comments

Comments

@steffen-kiess
Copy link

Starting with commit 5e8ad61 a table cell keeps track of its index. When creating a table cell with cmark_node_new_with_ext(), the cell_index value is not initialized anywhere. This will cause functions like cmark_render_html() and cmark_render_xml() to crash.

Example code:

#include <string.h>

#include <cmark-gfm.h>
#include <cmark-gfm-core-extensions.h>

const char* doc_str = "\n"
"| foo | bar |\n"
"| --- | --- |\n"
"| baz | bim |\n"
"";

int main() {
  cmark_gfm_core_extensions_ensure_registered();
  cmark_parser* parser = cmark_parser_new(0);
  cmark_parser_attach_syntax_extension(parser, cmark_find_syntax_extension("table"));
  cmark_parser_feed(parser, doc_str, strlen(doc_str));
  cmark_node* doc = cmark_parser_finish(parser);

  const char* html = cmark_render_html(doc, 0, 0);
  printf("%s\n", html);

  const char* xml = cmark_render_xml(doc, 0);
  printf("%s\n", xml);

  cmark_node* table = cmark_node_first_child(doc);
  cmark_node* header = cmark_node_first_child(table);
  cmark_node* cell = cmark_node_first_child(header);
  printf("cell is a '%s'\n", cmark_node_get_type_string(cell));

  cmark_node* new_cell = cmark_node_new_with_ext(cmark_node_get_type(cell), cmark_node_get_syntax_extension(cell));
  printf("new_cell is a '%s'\n", cmark_node_get_type_string(new_cell));

  cmark_node_prepend_child(header, new_cell);
  cmark_node_unlink(cell);

  const char* html2 = cmark_render_html(doc, 0, 0);
  printf("%s\n", html2);

  const char* xml2 = cmark_render_xml(doc, 0);
  printf("%s\n", xml2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant