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

Crashes when parsing AST of table with caption. #11

Open
xfbs opened this issue Jan 3, 2021 · 3 comments
Open

Crashes when parsing AST of table with caption. #11

xfbs opened this issue Jan 3, 2021 · 3 comments

Comments

@xfbs
Copy link
Contributor

xfbs commented Jan 3, 2021

Hey,

really awesome work here! I noticed a crash when parsing the AST of this table tho:

| First Header | Second Header |
|:-------------|:--------------|
| Content Cell | Content Cell  |

: Table example {#tbl:table1}

thread '' panicked at 'json is not in the pandoc format: Error("invalid type: map, expected a tuple of size 2", line: 283, column: 5)

Here is the raw JSON:

{
  "blocks": [
    {
      "t": "Table",
      "c": [
        [
          "",
          [],
          []
        ],
        {
          "t": "Caption",
          "c": [
            null,
            [
              {
                "t": "Plain",
                "c": [
                  {
                    "t": "Str",
                    "c": "Table"
                  },
                  {
                    "t": "Space"
                  },
                  {
                    "t": "Str",
                    "c": "example"
                  },
                  {
                    "t": "Space"
                  },
                  {
                    "t": "Str",
                    "c": "{#tbl:table1}"
                  }
                ]
              }
            ]
          ]
        },
        [
          [
            {
              "t": "AlignLeft"
            },
            {
              "t": "ColWidthDefault"
            }
          ],
          [
            {
              "t": "AlignLeft"
            },
            {
              "t": "ColWidthDefault"
            }
          ]
        ],
        {
          "t": "TableHead",
          "c": [
            [
              "",
              [],
              []
            ],
            [
              {
                "t": "Row",
                "c": [
                  [
                    "",
                    [],
                    []
                  ],
                  [
                    {
                      "t": "Cell",
                      "c": [
                        [
                          "",
                          [],
                          []
                        ],
                        {
                          "t": "AlignDefault"
                        },
                        {
                          "t": "RowSpan",
                          "c": 1
                        },
                        {
                          "t": "ColSpan",
                          "c": 1
                        },
                        [
                          {
                            "t": "Plain",
                            "c": [
                              {
                                "t": "Str",
                                "c": "First"
                              },
                              {
                                "t": "Space"
                              },
                              {
                                "t": "Str",
                                "c": "Header"
                              }
                            ]
                          }
                        ]
                      ]
                    },
                    {
                      "t": "Cell",
                      "c": [
                        [
                          "",
                          [],
                          []
                        ],
                        {
                          "t": "AlignDefault"
                        },
                        {
                          "t": "RowSpan",
                          "c": 1
                        },
                        {
                          "t": "ColSpan",
                          "c": 1
                        },
                        [
                          {
                            "t": "Plain",
                            "c": [
                              {
                                "t": "Str",
                                "c": "Second"
                              },
                              {
                                "t": "Space"
                              },
                              {
                                "t": "Str",
                                "c": "Header"
                              }
                            ]
                          }
                        ]
                      ]
                    }
                  ]
                ]
              }
            ]
          ]
        },
        [
          {
            "t": "TableBody",
            "c": [
              [
                "",
                [],
                []
              ],
              {
                "t": "RowHeadColumns",
                "c": 0
              },
              [],
              [
                {
                  "t": "Row",
                  "c": [
                    [
                      "",
                      [],
                      []
                    ],
                    [
                      {
                        "t": "Cell",
                        "c": [
                          [
                            "",
                            [],
                            []
                          ],
                          {
                            "t": "AlignDefault"
                          },
                          {
                            "t": "RowSpan",
                            "c": 1
                          },
                          {
                            "t": "ColSpan",
                            "c": 1
                          },
                          [
                            {
                              "t": "Plain",
                              "c": [
                                {
                                  "t": "Str",
                                  "c": "Content"
                                },
                                {
                                  "t": "Space"
                                },
                                {
                                  "t": "Str",
                                  "c": "Cell"
                                }
                              ]
                            }
                          ]
                        ]
                      },
                      {
                        "t": "Cell",
                        "c": [
                          [
                            "",
                            [],
                            []
                          ],
                          {
                            "t": "AlignDefault"
                          },
                          {
                            "t": "RowSpan",
                            "c": 1
                          },
                          {
                            "t": "ColSpan",
                            "c": 1
                          },
                          [
                            {
                              "t": "Plain",
                              "c": [
                                {
                                  "t": "Str",
                                  "c": "Content"
                                },
                                {
                                  "t": "Space"
                                },
                                {
                                  "t": "Str",
                                  "c": "Cell"
                                }
                              ]
                            }
                          ]
                        ]
                      }
                    ]
                  ]
                }
              ]
            ]
          }
        ],
        {
          "t": "TableFoot",
          "c": [
            [
              "",
              [],
              []
            ],
            []
          ]
        }
      ]
    }
  ],
  "pandoc-api-version": [
    1,
    21
  ],
  "meta": {}
}

I hope that is enough information to reproduce this issue. I'm using pandoc version 2.10.1, pandoc crate 0.8.2 and pandoc-ast 0.8.0.

@oli-obk
Copy link
Owner

oli-obk commented Jan 3, 2021

I took the liberty of formatting your json to make it easier to read.

So I believe the issue is that the format changed and I should have updated pandoc-ast to handle the pandoc-api-version change to use structs instead of tuples (TableFoot, TableBody, TableHead and Caption at least should now be structs that eat up the "t": "TableFoot" and similar. I don't have the time and setup to work on this right now, so any implementation work would be appreciated.

@xfbs
Copy link
Contributor Author

xfbs commented Jan 4, 2021

Thanks for looking into it, I already figured that it might be due to some change in the serialisation. I'll take a look at the code tomorrow and see if I can implement anything useful, should probably be able to get it fixed and tested tomorrow, I'll send a pull request your way if I make any useful progress.

@shonfeder
Copy link

shonfeder commented Mar 10, 2021

Just noting that, afaict, this crashes result from any tables at all, whether or not they have captions. At least against pandoc 2.9.2.1 (using pandoc_ast 0.8.0).

Here's failing table:

| A | B | C |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 2 | 2 |

Which (when using filter) panics with:

thread 'main' panicked at 'json is not in the pandoc format: Error("invalid length 0, expected a tuple of size 3", line: 1350, column: 5)

I don't mean to add to your workload, but I think it could be helpful for users to add a warning to the readme noting that support for the pandoc api is not actively maintained, and indicating the current maximum pandoc version supported.

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

3 participants