Comparing version 2.0.0 to 2.1.0
@@ -46,6 +46,7 @@ (function () { | ||
parse: function(value, callback) { | ||
parse: function(string, callback) { | ||
var result = {}, | ||
r = /(["])(?:\\\1|.)*?\1/g, | ||
matches = value.match(r), | ||
//using [\s\S] to match any character, including line feed and carriage return, | ||
r = /(["])(?:\\\1|[\s\S])*?\1|NULL/g, | ||
matches = string.match(r), | ||
i, | ||
@@ -61,3 +62,5 @@ l, | ||
for (i = 0, l = matches.length; i < l; i+= 2) { | ||
result[clean(matches[i])] = clean(matches[i + 1]); | ||
var key = clean(matches[i]); | ||
var value = matches[i + 1]; | ||
result[key] = value=="NULL"?null:clean(value); | ||
} | ||
@@ -64,0 +67,0 @@ if (!callback || callback === null) return result; |
@@ -7,3 +7,3 @@ { | ||
"keywords": ["pg", "postgres", "hstore"], | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"main": "lib/index.js", | ||
@@ -10,0 +10,0 @@ "homepage": "https://github.com/scarney81/pg-hstore", |
@@ -6,2 +6,3 @@ /*globals it, describe, beforeEach */ | ||
var should = require('should'), | ||
assert= require('assert'), | ||
HStore = require('../lib/index.js'), | ||
@@ -61,3 +62,25 @@ hstore; | ||
}); | ||
it('should hstore parse a string with NULL values', function (done) { | ||
var source = '"foo"=>"oof","bar"=>NULL,"baz"=>"zab"'; | ||
hstore.parse(source, function (target) { | ||
should.exist(target); | ||
target.foo.should.equal('oof'); | ||
assert.equal(target.bar, null); | ||
target.baz.should.equal('zab'); | ||
done(); | ||
}); | ||
}); | ||
it('should hstore parse a string with \n values', function (done) { | ||
var source = '"foo"=>"o\rof","bar"=>NULL,"baz"=>"z\nab"'; | ||
hstore.parse(source, function (target) { | ||
should.exist(target); | ||
target.foo.should.equal('o\rof'); | ||
assert.equal(target.bar, null); | ||
target.baz.should.equal('z\nab'); | ||
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
16730
231