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

Support non-String attributes #930

Open
atjn opened this issue Mar 7, 2023 · 0 comments
Open

Support non-String attributes #930

atjn opened this issue Mar 7, 2023 · 0 comments

Comments

@atjn
Copy link

atjn commented Mar 7, 2023

Hello and thank you for making these tools :)

If you add a non-String attribute to any node and ask dom-serializer to parse it, it will treat the attribute value as a string and quickly throw an error.
Here is a condensed example: https://runkit.com/atjn/64073ea61e340b000802a5cd

In my case, I am trying to add a width and height to an SVG node. I know that these values are technically speaking strings, but they are supposed to be parsed as numbers, so I think it makes sense that I can set them to a Number without breaking the parser. This is also how the normal DOM APIs work in JS.

Therefore I would suggest adding a quick conversion to string before encoding the attributes.

If you don't think the parser should support non-string values, then I would suggest adding a check that throws a more concise error. The current one is very hard to decipher:

file:///[...]/node_modules/entities/lib/esm/escape.js:46
    return ret + str.substr(lastIdx);
                     ^

TypeError: str.substr is not a function
    at encodeXML (file:///[...]/node_modules/entities/lib/esm/escape.js:46:22)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant