Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion handlers/convertString.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ exports.process = function(config) {
}

config.data = _.map(config.data, function(datum) {
var escapeChar = config.string && config.string.escapeChar ?
config.string.escapeChar : '\'';

var parts = _.map(datum, function(value, key) {
key = String(key).replace('-', '_').replace(/\W/g, '');
value = String(value).replace(/\n/g, ' ');
value = String(value).replace(/\n/g, ' ').replace(/"/g, escapeChar);
return key + '="' + value + '"';
});

Expand Down
37 changes: 37 additions & 0 deletions test/convertString.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,42 @@ describe('handler/convertString.js', function() {
done();
});
});

it('should escape double quote characters',
function(done) {
var config = {
data: [{test: 'this is "a" test.'}],
setting: true
};
dataString = "test=\"this is 'a' test.\"\n";
handler.process(config)
.then(function(result) {
assert.ok(result.hasOwnProperty('setting'),
'process returns config object');
assert.equal(result.data, dataString,
'converted to string with prefix and suffix successfully');
done();
});
});

it('should support a configurable escape character',
function(done) {
var config = {
data: [{test: 'this is "a" test.'}],
setting: true,
string: {
escapeChar: 'x'
}
};
dataString = "test=\"this is xax test.\"\n";
handler.process(config)
.then(function(result) {
assert.ok(result.hasOwnProperty('setting'),
'process returns config object');
assert.equal(result.data, dataString,
'converted to string with prefix and suffix successfully');
done();
});
});
});
});