mysql2 3.9.4 → 3.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helpers.js +13 -3
- package/lib/parsers/binary_parser.js +15 -14
- package/lib/parsers/text_parser.js +9 -10
- package/package.json +1 -1
package/lib/helpers.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
function srcEscape(str) {
|
|
18
18
|
return JSON.stringify({
|
|
19
|
-
[str]: 1
|
|
19
|
+
[str]: 1,
|
|
20
20
|
}).slice(1, -3);
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -29,7 +29,7 @@ try {
|
|
|
29
29
|
const REQUIRE_TERMINATOR = '';
|
|
30
30
|
highlightFn = require(`cardinal${REQUIRE_TERMINATOR}`).highlight;
|
|
31
31
|
} catch (err) {
|
|
32
|
-
highlightFn = text => {
|
|
32
|
+
highlightFn = (text) => {
|
|
33
33
|
if (!cardinalRecommended) {
|
|
34
34
|
// eslint-disable-next-line no-console
|
|
35
35
|
console.log('For nicer debug output consider install cardinal@^2.0.0');
|
|
@@ -56,10 +56,20 @@ exports.printDebugWithCode = printDebugWithCode;
|
|
|
56
56
|
*/
|
|
57
57
|
function typeMatch(type, list, Types) {
|
|
58
58
|
if (Array.isArray(list)) {
|
|
59
|
-
return list.some(t => type === Types[t]);
|
|
59
|
+
return list.some((t) => type === Types[t]);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
return !!list;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
exports.typeMatch = typeMatch;
|
|
66
|
+
|
|
67
|
+
const privateObjectProps = new Set([
|
|
68
|
+
'__defineGetter__',
|
|
69
|
+
'__defineSetter__',
|
|
70
|
+
'__lookupGetter__',
|
|
71
|
+
'__lookupSetter__',
|
|
72
|
+
'__proto__',
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
exports.privateObjectProps = privateObjectProps;
|
|
@@ -122,13 +122,7 @@ function compile(fields, options, config) {
|
|
|
122
122
|
if (options.rowsAsArray) {
|
|
123
123
|
parserFn(`const result = new Array(${fields.length});`);
|
|
124
124
|
} else {
|
|
125
|
-
parserFn('const result =
|
|
126
|
-
parserFn(`Object.defineProperty(result, "constructor", {
|
|
127
|
-
value: Object.create(null),
|
|
128
|
-
writable: false,
|
|
129
|
-
configurable: false,
|
|
130
|
-
enumerable: false
|
|
131
|
-
});`);
|
|
125
|
+
parserFn('const result = {};');
|
|
132
126
|
}
|
|
133
127
|
|
|
134
128
|
// Global typeCast
|
|
@@ -152,6 +146,13 @@ function compile(fields, options, config) {
|
|
|
152
146
|
|
|
153
147
|
for (let i = 0; i < fields.length; i++) {
|
|
154
148
|
fieldName = helpers.srcEscape(fields[i].name);
|
|
149
|
+
|
|
150
|
+
if (helpers.privateObjectProps.has(fields[i].name)) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`The field name (${fieldName}) can't be the same as an object's private property.`,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
155
156
|
parserFn(`// ${fieldName}: ${typeNames[fields[i].columnType]}`);
|
|
156
157
|
|
|
157
158
|
if (typeof options.nestTables === 'string') {
|
|
@@ -160,9 +161,7 @@ function compile(fields, options, config) {
|
|
|
160
161
|
)}]`;
|
|
161
162
|
} else if (options.nestTables === true) {
|
|
162
163
|
tableName = helpers.srcEscape(fields[i].table);
|
|
163
|
-
parserFn(
|
|
164
|
-
`if (!result[${tableName}]) result[${tableName}] = Object.create(null);`,
|
|
165
|
-
);
|
|
164
|
+
parserFn(`if (!result[${tableName}]) result[${tableName}] = {};`);
|
|
166
165
|
lvalue = `result[${tableName}][${fieldName}]`;
|
|
167
166
|
} else if (options.rowsAsArray) {
|
|
168
167
|
lvalue = `result[${i.toString(10)}]`;
|
|
@@ -170,6 +169,10 @@ function compile(fields, options, config) {
|
|
|
170
169
|
lvalue = `result[${fieldName}]`;
|
|
171
170
|
}
|
|
172
171
|
|
|
172
|
+
parserFn(`if (nullBitmaskByte${nullByteIndex} & ${currentFieldNullBit}) `);
|
|
173
|
+
parserFn(`${lvalue} = null;`);
|
|
174
|
+
parserFn('else {');
|
|
175
|
+
|
|
173
176
|
if (options.typeCast === false) {
|
|
174
177
|
parserFn(`${lvalue} = packet.readLengthCodedBuffer();`);
|
|
175
178
|
} else {
|
|
@@ -177,9 +180,6 @@ function compile(fields, options, config) {
|
|
|
177
180
|
parserFn(`const ${fieldWrapperVar} = wrap(fields[${i}], packet);`);
|
|
178
181
|
const readCode = readCodeFor(fields[i], config, options, i);
|
|
179
182
|
|
|
180
|
-
parserFn(`if (nullBitmaskByte${nullByteIndex} & ${currentFieldNullBit})`);
|
|
181
|
-
parserFn(`${lvalue} = null;`);
|
|
182
|
-
parserFn('else {');
|
|
183
183
|
if (typeof options.typeCast === 'function') {
|
|
184
184
|
parserFn(
|
|
185
185
|
`${lvalue} = options.typeCast(${fieldWrapperVar}, function() { return ${readCode} });`,
|
|
@@ -187,8 +187,9 @@ function compile(fields, options, config) {
|
|
|
187
187
|
} else {
|
|
188
188
|
parserFn(`${lvalue} = ${readCode};`);
|
|
189
189
|
}
|
|
190
|
-
parserFn('}');
|
|
191
190
|
}
|
|
191
|
+
parserFn('}');
|
|
192
|
+
|
|
192
193
|
|
|
193
194
|
currentFieldNullBit *= 2;
|
|
194
195
|
if (currentFieldNullBit === 0x100) {
|
|
@@ -131,13 +131,7 @@ function compile(fields, options, config) {
|
|
|
131
131
|
if (options.rowsAsArray) {
|
|
132
132
|
parserFn(`const result = new Array(${fields.length});`);
|
|
133
133
|
} else {
|
|
134
|
-
parserFn('const result =
|
|
135
|
-
parserFn(`Object.defineProperty(result, "constructor", {
|
|
136
|
-
value: Object.create(null),
|
|
137
|
-
writable: false,
|
|
138
|
-
configurable: false,
|
|
139
|
-
enumerable: false
|
|
140
|
-
});`);
|
|
134
|
+
parserFn('const result = {};');
|
|
141
135
|
}
|
|
142
136
|
|
|
143
137
|
const resultTables = {};
|
|
@@ -149,9 +143,7 @@ function compile(fields, options, config) {
|
|
|
149
143
|
}
|
|
150
144
|
resultTablesArray = Object.keys(resultTables);
|
|
151
145
|
for (let i = 0; i < resultTablesArray.length; i++) {
|
|
152
|
-
parserFn(
|
|
153
|
-
`result[${helpers.srcEscape(resultTablesArray[i])}] = Object.create(null);`,
|
|
154
|
-
);
|
|
146
|
+
parserFn(`result[${helpers.srcEscape(resultTablesArray[i])}] = {};`);
|
|
155
147
|
}
|
|
156
148
|
}
|
|
157
149
|
|
|
@@ -159,6 +151,13 @@ function compile(fields, options, config) {
|
|
|
159
151
|
let fieldName = '';
|
|
160
152
|
for (let i = 0; i < fields.length; i++) {
|
|
161
153
|
fieldName = helpers.srcEscape(fields[i].name);
|
|
154
|
+
|
|
155
|
+
if (helpers.privateObjectProps.has(fields[i].name)) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`The field name (${fieldName}) can't be the same as an object's private property.`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
162
161
|
parserFn(`// ${fieldName}: ${typeNames[fields[i].columnType]}`);
|
|
163
162
|
if (typeof options.nestTables === 'string') {
|
|
164
163
|
lvalue = `result[${helpers.srcEscape(
|
package/package.json
CHANGED