Comparing version 2.1.2 to 2.2.0
@@ -12,4 +12,2 @@ (function () { | ||
input = input.replace(/"/g, '\\"'); | ||
// colons (:) must be replaced with escaped colons (\\:) | ||
input = input.replace(/:/g, '\\:'); | ||
return input; | ||
@@ -58,3 +56,9 @@ } | ||
// Unescape quotes | ||
return value.replace(/\\"/g, "\""); | ||
value = value.replace(/\\"/g, "\""); | ||
//Unescape backslashes | ||
value = value.replace(/\\\\/g,"\\"); | ||
//Unescape single quotes | ||
value = value.replace(/''/g,"'"); | ||
return value; | ||
}; | ||
@@ -61,0 +65,0 @@ |
@@ -7,3 +7,3 @@ { | ||
"keywords": ["pg", "postgres", "hstore"], | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"main": "lib/index.js", | ||
@@ -10,0 +10,0 @@ "homepage": "https://github.com/scarney81/pg-hstore", |
@@ -53,2 +53,20 @@ /*globals it, describe, beforeEach */ | ||
it('should hstore parse an escaped quoted string with single quotes', function (done) { | ||
var source = '"foo"=>"\'\'bar\'\'"'; | ||
hstore.parse(source, function (target) { | ||
should.exist(target); | ||
target.foo.should.equal('\'bar\''); | ||
done(); | ||
}); | ||
}); | ||
it('should hstore parse a string with escaped backslashes', function (done) { | ||
var source = '"foo"=>"\\\\f0123"'; | ||
hstore.parse(source, function (target) { | ||
should.exist(target); | ||
target.foo.should.equal('\\f0123'); | ||
done(); | ||
}); | ||
}); | ||
it('should hstore parse a string with commas', function (done) { | ||
@@ -55,0 +73,0 @@ var source = '"foo"=>"bar,foo,bar"'; |
@@ -10,96 +10,185 @@ /*globals it, describe, beforeEach */ | ||
describe('pg-hstore.stringify', function () { | ||
beforeEach(function () { | ||
hstore = new HStore(); | ||
}); | ||
describe('without sanitization', function(){ | ||
beforeEach(function () { | ||
hstore = new HStore(); | ||
}); | ||
it('should hstore encode a string', function (done) { | ||
var source = { foo: 'bar' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"bar"'); | ||
done(); | ||
it('should hstore encode a string', function (done) { | ||
var source = { foo: 'bar' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"bar"'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should hstore encode a number', function (done) { | ||
var source = { foo: 1000 }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"1000"'); | ||
done(); | ||
it('should hstore encode a number', function (done) { | ||
var source = { foo: 1000 }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"1000"'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should hstore encode a boolean', function (done) { | ||
var source = { foo: true }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"true"'); | ||
done(); | ||
it('should hstore encode a boolean', function (done) { | ||
var source = { foo: true }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"true"'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should hstore encode a null value', function (done) { | ||
var source = { foo: null }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>NULL'); | ||
done(); | ||
it('should hstore encode a null value', function (done) { | ||
var source = { foo: null }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>NULL'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should hstore encode a null string value', function (done) { | ||
var source = { foo: 'null' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"null"'); | ||
done(); | ||
it('should hstore encode a null string value', function (done) { | ||
var source = { foo: 'null' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"null"'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should hstore encode single quotes correctly', function (done) { | ||
var source = { 'foo \'quotes\'': 'with \'quotes\'' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo \'quotes\'"=>"with \'quotes\'"'); | ||
done(); | ||
it('should hstore encode single quotes correctly', function (done) { | ||
var source = { 'foo \'quotes\'': 'with \'quotes\'' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo \'quotes\'"=>"with \'quotes\'"'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should hstore encode double quotes correctly', function (done) { | ||
var source = { foo: 'with \"quotes\"' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"with "quotes""'); | ||
done(); | ||
it('should hstore encode double quotes correctly', function (done) { | ||
var source = { foo: 'with \"quotes\"' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"with "quotes""'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should hstore encode double quote keys correctly', function (done) { | ||
var source = { 'foo \"quotes\"': 'with \"quotes\"' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo "quotes""=>"with "quotes""'); | ||
done(); | ||
it('should hstore encode double quote keys correctly', function (done) { | ||
var source = { 'foo \"quotes\"': 'with \"quotes\"' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo "quotes""=>"with "quotes""'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should hstore encode colon correctly', function (done) { | ||
var source = { 'foo': 'with:colon' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"with:colon"'); | ||
done(); | ||
it('should hstore encode colon correctly', function (done) { | ||
var source = { 'foo': 'with:colon' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"with:colon"'); | ||
done(); | ||
}); | ||
}); | ||
it('should not sanitize output', function (done) { | ||
var source = { 'foo\'"\\': 'bar' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo\'"\\"=>"bar"'); | ||
done(); | ||
}, true); | ||
}); | ||
}); | ||
it('should not sanitize output', function (done) { | ||
var source = { 'foo\'"\\': 'bar' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo\'"\\"=>"bar"'); | ||
done(); | ||
}, true); | ||
describe('with sanitization', function(){ | ||
beforeEach(function () { | ||
hstore = new HStore({sanitize : true}); | ||
}); | ||
it('should hstore encode a string', function (done) { | ||
var source = { foo: 'bar' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"bar"'); | ||
done(); | ||
}); | ||
}); | ||
it('should hstore encode a number', function (done) { | ||
var source = { foo: 1000 }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"1000"'); | ||
done(); | ||
}); | ||
}); | ||
it('should hstore encode a boolean', function (done) { | ||
var source = { foo: true }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"true"'); | ||
done(); | ||
}); | ||
}); | ||
it('should hstore encode a null value', function (done) { | ||
var source = { foo: null }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>NULL'); | ||
done(); | ||
}); | ||
}); | ||
it('should hstore encode a null string value', function (done) { | ||
var source = { foo: 'null' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"null"'); | ||
done(); | ||
}); | ||
}); | ||
it('should hstore encode single quotes correctly', function (done) { | ||
var source = { 'foo \'quotes\'': 'with \'quotes\'' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo \'\'quotes\'\'"=>"with \'\'quotes\'\'"'); | ||
done(); | ||
}); | ||
}); | ||
it('should hstore encode double quotes correctly', function (done) { | ||
var source = { foo: 'with "quotes"' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"with \\"quotes\\""'); | ||
done(); | ||
}); | ||
}); | ||
it('should hstore encode backslashes correctly', function (done) { | ||
var source = { '\\f0122': '\\f0123' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"\\\\f0122"=>"\\\\f0123"'); | ||
done(); | ||
}); | ||
}); | ||
it('should hstore encode colon correctly', function (done) { | ||
var source = { 'foo': 'with:colon' }; | ||
hstore.stringify(source, function (target) { | ||
should.exist(target); | ||
target.should.equal('"foo"=>"with:colon"'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
})(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21272
11
348