Skip to content

toString() cannot handle non text attributes #34

@panthershark

Description

@panthershark

Scenario: I'm using virtual-dom and wanted to switch from vdom-to-html to using the toString() method for serializing.

However, there are places where we set numbers or booleans to attributes and toString() does not handle it.

var document = require('min-document');
var el = document.createElement('div')
el.value = 100
el.toString()

Error:

TypeError: str.replace is not a function
    at escapeText (/Users/tommy/src/web/cbw/node_modules/global/node_modules/min-document/serialize.js:135:6)
    at escapeAttributeValue (/Users/tommy/src/web/cbw/node_modules/global/node_modules/min-document/serialize.js:141:10)
    at /Users/tommy/src/web/cbw/node_modules/global/node_modules/min-document/serialize.js:95:41
    at Array.forEach (native)
    at stringify (/Users/tommy/src/web/cbw/node_modules/global/node_modules/min-document/serialize.js:87:8)
    at properties (/Users/tommy/src/web/cbw/node_modules/global/node_modules/min-document/serialize.js:130:25)
    at serializeElement (/Users/tommy/src/web/cbw/node_modules/global/node_modules/min-document/serialize.js:25:32)
    at serializeNode (/Users/tommy/src/web/cbw/node_modules/global/node_modules/min-document/serialize.js:12:12)
    at DOMElement._Element_toString [as toString] (/Users/tommy/src/web/cbw/node_modules/global/node_modules/min-document/dom-element.js:161:12)
    at repl:1:4

Question: If I send a PR, will you accept it?

I understand that the

  • the DOM spec expects attributes to be strings.
  • vdom's diff/patch handles non string attributes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions