Skip to content

Support non-String attributes #930

Open
@atjn

Description

@atjn

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions