Skip to content

Commit

Permalink
Fix "empty text" bug by the toStirng() method of the wrapped version …
Browse files Browse the repository at this point in the history
…xmlbuilder
  • Loading branch information
piroor committed Jul 19, 2012
1 parent aa2c199 commit d07b7c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lib/api/2011-02-01/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,12 @@ handlers.DefineIndexField = function(context, request, response) {
function createDeleteIndexFieldResponse(options) {
var doc = xmlbuilder.create();

// This is a workaround for the problem that text() does not work when empty string is given.
// https://github.com/oozcitak/xmlbuilder-js/pull/19
var requestId = doc.begin('DeleteIndexFieldResponse', {version: '1.0'}).attribute('xmlns', XMLNS)
.element('DeleteIndexFieldResult')
.up()
doc.begin('DeleteIndexFieldResponse', {version: '1.0'})
.attribute('xmlns', XMLNS)
.element('DeleteIndexFieldResult').up()
.element('ResponseMetadata')
.element('RequestId');

if (options.requestId && options.requestId !== '') {
requestId.text(options.requestId);
}
.element('RequestId').text(options.requestId || '').up()
.up();

return doc.toString();
}
Expand Down
9 changes: 9 additions & 0 deletions lib/xmlbuilder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
module.exports = require('xmlbuilder');
module.exports.XMLFragment = require('xmlbuilder/lib/XMLFragment');

module.exports.XMLFragment.prototype.addFragment = function(fragment) {
fragment.parent = this;
this.children.push(fragment);
return this;
};

// This is a workaround for the problem that text() does not work when empty string is given.
// https://github.com/oozcitak/xmlbuilder-js/pull/19
var originalToString = module.exports.XMLFragment.prototype.toString;
module.exports.XMLFragment.prototype.toString = function() {
var string = originalToString.apply(this, arguments);
return string.replace(/<\/>/g, '');
};

0 comments on commit d07b7c6

Please sign in to comment.