Comparing version 2.2.2 to 2.2.3
@@ -20,3 +20,3 @@ "use strict"; | ||
function makeIdentifierNode(names) { | ||
if (!Array.isArray(names) || !names.every(isStringOrSymbol)) { | ||
if (!Array.isArray(names) || names.length === 0 || !names.every(isStringOrSymbol)) { | ||
throw new Error("Invalid argument to makeIdentifierNode - expected array of strings/symbols"); | ||
@@ -58,15 +58,8 @@ } | ||
for (let itemIndex = 0; itemIndex < itemCount; itemIndex++) { | ||
const rawItem = items[itemIndex]; | ||
const item = enforceValidNode(rawItem); | ||
const item = enforceValidNode(items[itemIndex]); | ||
switch (item.type) { | ||
case "RAW": | ||
if (typeof item.text !== "string") { | ||
throw new Error("RAW node expected string"); | ||
} | ||
sqlFragments[itemIndex] = item.text; | ||
break; | ||
case "IDENTIFIER": | ||
if (item.names.length === 0) { | ||
throw new Error("Identifier must have a name"); | ||
} | ||
case "IDENTIFIER": { | ||
const nameCount = item.names.length; | ||
@@ -97,2 +90,3 @@ const mappedNames = new Array(nameCount); | ||
break; | ||
} | ||
case "VALUE": | ||
@@ -114,3 +108,3 @@ values.push(item.value); | ||
function enforceValidNode(node) { | ||
if (node !== null && typeof node === "object" && node[$$trusted] === true) { | ||
if (node !== null && node[$$trusted] === true) { | ||
return node; | ||
@@ -248,9 +242,5 @@ } | ||
// Trivial performance optimisations by Benjie. | ||
// Replaced with regexp because it's 11x faster by Benjie. | ||
function escapeSqlIdentifier(str) { | ||
let escaped = ""; | ||
for (let i = 0, l = str.length; i < l; i++) { | ||
const c = str[i]; | ||
escaped += c === '"' ? '""' : c; | ||
} | ||
return '"' + escaped + '"'; | ||
return `"${str.replace(/"/g, '""')}"`; | ||
} | ||
@@ -257,0 +247,0 @@ exports.escapeSqlIdentifier = escapeSqlIdentifier; |
{ | ||
"name": "pg-sql2", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"description": "Generate safe Postgres-compliant SQL with tagged template literals", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
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
26141
304