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

Building w/ emoji throws exception #98

Closed
dwbruhn opened this issue Jan 6, 2016 · 2 comments
Closed

Building w/ emoji throws exception #98

dwbruhn opened this issue Jan 6, 2016 · 2 comments
Labels

Comments

@dwbruhn
Copy link

dwbruhn commented Jan 6, 2016

I tried your example code, but with emoji:

var builder = require('xmlbuilder');
var xml = builder.create('root')
  .ele('xmlbuilder')
    .ele('repo', {'type': 'git'}, 'test 🐀 here')
  .end({ pretty: true});

console.log(xml);

And got this:

/Users/dbruhn/repos/testXML/node_modules/xmlbuilder/lib/XMLStringifier.js:149
        throw new Error("Invalid character (" + chr + ") in string: " + str +
              ^
Error: Invalid character (�) in string: test 🐀 here at index 5
    at XMLStringifier.module.exports.XMLStringifier.assertLegalChar (/Users/dbruhn/repos/testXML/node_modules/xmlbuilder/lib/XMLStringifier.js:149:15)
    at XMLStringifier.assertLegalChar (/Users/dbruhn/repos/testXML/node_modules/xmlbuilder/lib/XMLStringifier.js:4:59)
    at XMLStringifier.module.exports.XMLStringifier.eleText (/Users/dbruhn/repos/testXML/node_modules/xmlbuilder/lib/XMLStringifier.js:28:19)
    at new XMLText (/Users/dbruhn/repos/testXML/node_modules/xmlbuilder/lib/XMLText.js:19:35)
    at XMLElement.module.exports.XMLNode.text (/Users/dbruhn/repos/testXML/node_modules/xmlbuilder/lib/XMLNode.js:165:15)
    at XMLElement.module.exports.XMLNode.node (/Users/dbruhn/repos/testXML/node_modules/xmlbuilder/lib/XMLNode.js:157:15)
    at XMLElement.module.exports.XMLNode.element (/Users/dbruhn/repos/testXML/node_modules/xmlbuilder/lib/XMLNode.js:100:28)
    at XMLElement.module.exports.XMLNode.ele (/Users/dbruhn/repos/testXML/node_modules/xmlbuilder/lib/XMLNode.js:268:19)
    at Object.<anonymous> (/Users/dbruhn/repos/testXML/index.js:4:6)
    at Module._compile (module.js:456:26)

Any plans to support emoji? 😄

@oozcitak
Copy link
Owner

oozcitak commented Jan 6, 2016

Of course we support emoji 😄 but you need to set the allowSurrogateChars flag, e.g.:

var xml = builder.create('root', { allowSurrogateChars: true })

@dwbruhn
Copy link
Author

dwbruhn commented Jan 6, 2016

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants