Skip to content

Commit 0e433dd

Browse files
eg-opspatricklodder
authored andcommitted
Merge pull request #127 from g-gabber/master
Allows usage of Emoji's in string values 0e307e7 added allowSurrogateChars as default option for xmlBuilder 7d44897 added emoji tests 4deb82a replace the unicode string construction in the test files
1 parent 4957a24 commit 0e433dd

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

lib/serializer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var xmlBuilder = require('xmlbuilder')
1515
exports.serializeMethodCall = function(method, params, encoding) {
1616
var params = params || []
1717

18-
var options = { version: '1.0' }
18+
var options = { version: '1.0', allowSurrogateChars: true }
1919

2020
if (encoding) {
2121
options.encoding = encoding
@@ -45,7 +45,7 @@ exports.serializeMethodCall = function(method, params, encoding) {
4545
* - {String} xml - The method response XML.
4646
*/
4747
exports.serializeMethodResponse = function(result) {
48-
var xml = xmlBuilder.create('methodResponse', { version: '1.0' })
48+
var xml = xmlBuilder.create('methodResponse', { version: '1.0', allowSurrogateChars: true })
4949
.ele('params')
5050
.ele('param')
5151

@@ -56,7 +56,7 @@ exports.serializeMethodResponse = function(result) {
5656
}
5757

5858
exports.serializeFault = function(fault) {
59-
var xml = xmlBuilder.create('methodResponse', { version: '1.0' })
59+
var xml = xmlBuilder.create('methodResponse', { version: '1.0', allowSurrogateChars: true })
6060
.ele('fault')
6161

6262
serializeValue(fault, xml)
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0"?><methodCall><methodName>testMethod</methodName><params><param><value><string>😁</string></value></param></params></methodCall>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0"?><methodResponse><params><param><value><string>😁</string></value></param></params></methodResponse>

test/serializer_test.js

+14
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ vows.describe('Serializer').addBatch({
129129
}
130130
, 'contains the empty string': assertXml('good_food/string_empty_call.xml')
131131
}
132+
, 'with a string contains emoji': {
133+
topic: function () {
134+
var value = new Buffer('f09f9881', 'hex').toString('utf-8')
135+
return Serializer.serializeMethodCall('testMethod', [value])
136+
}
137+
, 'contains a smiley' : assertXml('good_food/string_emoji.xml')
138+
}
132139
}
133140

134141
, 'undefined' : {
@@ -319,6 +326,13 @@ vows.describe('Serializer').addBatch({
319326
}
320327
, 'contains the empty string': assertXml('good_food/string_empty_response.xml')
321328
}
329+
, 'with string contains emoji' : {
330+
topic: function () {
331+
var value = new Buffer('f09f9881', 'hex').toString('utf-8')
332+
return Serializer.serializeMethodResponse(value)
333+
}
334+
, 'contains emoji': assertXml('good_food/string_emoji_response.xml')
335+
}
322336
}
323337

324338
, 'undefined' : {

0 commit comments

Comments
 (0)