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

[Bug]: Ordered lists produce "order":null in json and throw when consumed #592

Open
lehmamic opened this issue Jan 27, 2025 · 1 comment

Comments

@lehmamic
Copy link

What happened?

We have entries in the database containing an ordered list content with an order = null value:

"type": "ordered_list",
"attrs": {
    "order": null
},

We never processed those strings, they get stored straight of of the ngx-editor via Angular form control. I don't know whether it is valid to have a null value in this place or if its a bug. The problem is more when reading in this rtf json and displaying it within the ngx-editor again, it will throw an exception when the order is set to null.

ERROR RangeError: Expected value of type number for attribute order on type ordered_list, got null
    at st.validate (231.d37ef6056f1f65d5.js:1:219940)
    at Rt (231.d37ef6056f1f65d5.js:1:217090)
    at ot.checkAttrs (231.d37ef6056f1f65d5.js:1:218915)
    at F.fromJSON (231.d37ef6056f1f65d5.js:1:210012)
    at Ue.nodeFromJSON (231.d37ef6056f1f65d5.js:1:222338)
    at Array.map (<anonymous>)
    at ne.fromJSON (231.d37ef6056f1f65d5.js:1:196222)
    at F.fromJSON (231.d37ef6056f1f65d5.js:1:209935)
    at Ue.nodeFromJSON (231.d37ef6056f1f65d5.js:1:222338)
    at jt (231.d37ef6056f1f65d5.js:1:137

Version

v18.0.0

Angular Version

v18.2.13

What browsers are you seeing the problem on?

Firefox, Chrome, Safari

Link to reproduce

No response

Relevant log output

ERROR RangeError: Expected value of type number for attribute order on type ordered_list, got null
    at st.validate (231.d37ef6056f1f65d5.js:1:219940)
    at Rt (231.d37ef6056f1f65d5.js:1:217090)
    at ot.checkAttrs (231.d37ef6056f1f65d5.js:1:218915)
    at F.fromJSON (231.d37ef6056f1f65d5.js:1:210012)
    at Ue.nodeFromJSON (231.d37ef6056f1f65d5.js:1:222338)
    at Array.map (<anonymous>)
    at ne.fromJSON (231.d37ef6056f1f65d5.js:1:196222)
    at F.fromJSON (231.d37ef6056f1f65d5.js:1:209935)
    at Ue.nodeFromJSON (231.d37ef6056f1f65d5.js:1:222338)
    at jt (231.d37ef6056f1f65d5.js:1:137

Willing to submit a PR?

None

@MG-SNF
Copy link

MG-SNF commented Feb 20, 2025

This issue can be reproduced by entering "1." followed by a space and then text (e.g., "Test"). This automatically converts the input into a numbered list. However, the generated HTML is:

<ol start="NaN"><li><p>Test</p></li></ol>

In contrast, if we use the "Numbered List" option from the menu, the generated HTML is: <ol><li><p>Test</p></li></ol>

The presence of NaN in the attribute leads to a null value when converting to JSON:

"ordered_list",
      "attrs": {
        "order": null
      },
      "content": [
        {
          "type": "list_item",
          "content": [
            {
              "type": "paragraph",
              "attrs": {
                "align": null,
                "indent": null
              },
              "content": [
                {
                  "type": "text",
                  "text": "Test"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

See Example with "keyboard"

Image

See Example with menu

Image

You can try it on Stackblitz

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

2 participants