New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hapiest-mysql

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapiest-mysql - npm Package Compare versions

Comparing version 0.0.15 to 0.0.16

18

lib/mysqlDao.js

@@ -24,2 +24,7 @@ 'use strict';

/**
* @returns {MysqlService}
*/
get mysqlService() { return this._mysqlService; }
/**
* @param {object} createArgs

@@ -141,4 +146,17 @@ * @returns {Promise.<int,Error>} - ID of last inserted item

/**
* @param uncleanValue
* @returns {string|number}
*/
clean(uncleanValue) { return this._queryHelper.clean(uncleanValue); }
/**
*
* @param uncleanValue
* @returns {string|number}
*/
cleanSpecial(uncleanValue) { return this._queryHelper.cleanSpecial(uncleanValue); }
}
module.exports = MysqlDao;

35

lib/mysqlDaoQueryHelper.js

@@ -79,2 +79,27 @@ 'use strict';

/**
* Raw MySQL clean function
* @param uncleanValue
* @returns {string|number}
*/
clean(uncleanValue) {
return this._clean(uncleanValue);
}
/**
* Allows special MySQL functions to pass through without getting cleaned
* @param uncleanValue
* @returns {string|number}
*/
cleanSpecial(uncleanValue) {
let cleanValue = null;
if (_.includes(['current_timestamp','now()'],_.toLower(uncleanValue))) {
cleanValue = uncleanValue;
} else {
const valueToClean = typeof(uncleanValue) === 'undefined' ? null : uncleanValue;
cleanValue = this._clean(valueToClean);
}
return cleanValue;
}
/**
* @param {object} whereClause

@@ -155,11 +180,3 @@ * @returns {Squel}

const snakeCaseProperty = _.snakeCase(property);
let cleanValue = null;
if (config.dontCleanMysqlFunctions && _.includes(['current_timestamp','now()'],_.toLower(uncleanValue))) {
cleanValue = uncleanValue;
} else {
const valueToClean = typeof(uncleanValue) === 'undefined' ? null : uncleanValue;
cleanValue = this._clean(valueToClean);
}
const cleanValue = config.dontCleanMysqlFunctions ? this.cleanSpecial(uncleanValue) : this.clean(uncleanValue) ;
cleanValues[snakeCaseProperty] = cleanValue;

@@ -166,0 +183,0 @@ }

{
"name": "hapiest-mysql",
"version": "0.0.15",
"version": "0.0.16",
"description": "A wrapper around mysql that provides a very descriptive way of running queries.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -375,3 +375,51 @@ 'use strict';

describe('clean', function() {
it('Should clean value passed in', function() {
const uncleanValue = "some unclean value with ' single quote";
const cleanValue = userDao.clean(uncleanValue);
Should.exist(cleanValue);
cleanValue.should.eql("'some unclean value with \\' single quote'");
});
it('Should escape all strings, even special MySQL functions', function() {
const currentTimestampUnclean = "current_timestamp";
const currentTimestampClean = userDao.clean(currentTimestampUnclean);
Should.exist(currentTimestampClean);
currentTimestampClean.should.eql("'current_timestamp'");
const nowUnclean = "NOW()";
const nowClean = userDao.clean(nowUnclean);
Should.exist(nowClean);
nowClean.should.eql("'NOW()'");
});
});
describe('cleanSpecial', function() {
it('Should clean value passed in', function() {
const uncleanValue = "some unclean value with ' single quote";
const cleanValue = userDao.cleanSpecial(uncleanValue);
Should.exist(cleanValue);
cleanValue.should.eql("'some unclean value with \\' single quote'");
});
it('Should allow special MySQL functions to pass through uncleaned', function() {
const currentTimestampUnclean = "current_timestamp";
const currentTimestampClean = userDao.cleanSpecial(currentTimestampUnclean);
Should.exist(currentTimestampClean);
currentTimestampClean.should.eql("current_timestamp");
const nowUnclean = "NOW()";
const nowClean = userDao.cleanSpecial(nowUnclean);
Should.exist(nowClean);
nowClean.should.eql("NOW()");
});
});
});

@@ -155,2 +155,50 @@ 'use strict';

describe('clean', function() {
it('Should clean value passed in', function() {
const uncleanValue = "some unclean value with ' single quote";
const cleanValue = mysqlDaoQueryHelper.clean(uncleanValue);
Should.exist(cleanValue);
cleanValue.should.eql("'some unclean value with \\' single quote'");
});
it('Should escape all strings, even special MySQL functions', function() {
const currentTimestampUnclean = "current_timestamp";
const currentTimestampClean = mysqlDaoQueryHelper.clean(currentTimestampUnclean);
Should.exist(currentTimestampClean);
currentTimestampClean.should.eql("'current_timestamp'");
const nowUnclean = "NOW()";
const nowClean = mysqlDaoQueryHelper.clean(nowUnclean);
Should.exist(nowClean);
nowClean.should.eql("'NOW()'");
});
});
describe('cleanSpecial', function() {
it('Should clean value passed in', function() {
const uncleanValue = "some unclean value with ' single quote";
const cleanValue = mysqlDaoQueryHelper.cleanSpecial(uncleanValue);
Should.exist(cleanValue);
cleanValue.should.eql("'some unclean value with \\' single quote'");
});
it('Should allow special MySQL functions to pass through uncleaned', function() {
const currentTimestampUnclean = "current_timestamp";
const currentTimestampClean = mysqlDaoQueryHelper.cleanSpecial(currentTimestampUnclean);
Should.exist(currentTimestampClean);
currentTimestampClean.should.eql("current_timestamp");
const nowUnclean = "NOW()";
const nowClean = mysqlDaoQueryHelper.cleanSpecial(nowUnclean);
Should.exist(nowClean);
nowClean.should.eql("NOW()");
});
});
describe('_cleanAndMapValues', function() {

@@ -157,0 +205,0 @@

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