Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pg-hstore

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-hstore - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

42

lib/index.js

@@ -41,28 +41,16 @@ var sanitize_input = function(input) {

parse: function(value, callback) {
var result = {};
var ke = value.length,
vs = value.length,
ve = value.length,
key, val;
var buf = '';
var i = value.length;
//work backwards through string
while (i > -1) {
buf = value.slice(i - 2, i);
if (buf == '=>' || i === 0) {
vs = i;
ve = (value.lastIndexOf(',') == -1) ? value.length : value.lastIndexOf(',');
if (i === 0) {
ke = value.indexOf('=>');
ve = -1;
}
if (val) {
key = value.slice(ve + 1, ke).trim().slice(1, - 1);
value = value.slice(0, ve);
result[key] = val;
}
val = value.slice(vs, value.length).trim().slice(1, - 1);
ke = i - 2;
}
i--;
var result = {},
r = /(["])(?:\\\1|.)*?\1/g,
matches = value.match(r),
i,
l,
clean = function (value) {
// Remove leading double quotes
value = value.replace(/^\"|\"$/g, "");
// Unescape quotes
return value.replace(/\\"/g, "\"");
};
for (i = 0, l = matches.length; i < l; i+= 2) {
result[clean(matches[i])] = clean(matches[i + 1]);
}

@@ -72,2 +60,2 @@ if (!callback || callback === null) return result;

}
};
};

@@ -7,3 +7,3 @@ {

"keywords": ["pg", "postgres", "hstore"],
"version": "1.0.4",
"version": "1.1.0",
"main": "lib/index.js",

@@ -23,4 +23,4 @@ "homepage": "https://github.com/scarney81/pg-hstore",

"engines": {
"node": ">= 0.6.11"
"node": ">= 0.8.x"
}
}

@@ -26,5 +26,5 @@ /*globals it, describe */

});
it('should hstore parse an escaped quoted string with quotes', function(done) {
var source = '"foo"=>"\"bar\""';
var source = '"foo"=>"\\"bar\\""';
hstore.parse(source, function(target) {

@@ -36,3 +36,3 @@ should.exist(target);

});
it('should hstore parse a string with commas', function(done) {

@@ -46,5 +46,5 @@ var source = '"foo"=>"bar,foo,bar"';

});
it('should hstore parse a string with advanced types', function(done) {
var source = '"foo"=>"{"key":"value","key2":"value"}"';
var source = '"foo"=>"{\\"key\\":\\"value\\",\\"key2\\":\\"value\\"}"';
hstore.parse(source, function(target) {

@@ -56,2 +56,2 @@ should.exist(target);

});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc