shelving 1.267.1 → 1.267.2
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/package.json +1 -1
- package/schema/StringSchema.js +5 -2
- package/util/validate.js +4 -1
package/package.json
CHANGED
package/schema/StringSchema.js
CHANGED
|
@@ -31,12 +31,15 @@ export class StringSchema extends Schema {
|
|
|
31
31
|
if (typeof str !== "string")
|
|
32
32
|
throw value ? `Must be ${this.one}` : "Required";
|
|
33
33
|
const sane = this.sanitize(str);
|
|
34
|
+
// Enforce `max` before running `match`, so an over-length string is rejected without ever being handed to
|
|
35
|
+
// the (potentially expensive) regex — a length cap can't shield the pattern otherwise. `min` stays after
|
|
36
|
+
// `match` to preserve the existing "Invalid" precedence for short-but-malformed values.
|
|
37
|
+
if (sane.length > this.max)
|
|
38
|
+
throw `Maximum ${this.max} characters`;
|
|
34
39
|
if (this.match && !this.match.test(sane))
|
|
35
40
|
throw str.length ? `Invalid ${this.one}` : "Required";
|
|
36
41
|
if (sane.length < this.min)
|
|
37
42
|
throw str.length ? `Minimum ${this.min} characters` : "Required";
|
|
38
|
-
if (sane.length > this.max)
|
|
39
|
-
throw `Maximum ${this.max} characters`;
|
|
40
43
|
return sane;
|
|
41
44
|
}
|
|
42
45
|
/**
|
package/util/validate.js
CHANGED
|
@@ -124,7 +124,10 @@ export function validateArray(unsafeArray, validator) {
|
|
|
124
124
|
*/
|
|
125
125
|
export function validateDictionary(unsafeDictionary, validator) {
|
|
126
126
|
let changed = false;
|
|
127
|
-
|
|
127
|
+
// Null-prototype accumulator: an untrusted `"__proto__"` key (or `"constructor"`) then becomes an inert own
|
|
128
|
+
// property instead of invoking the inherited `__proto__` setter, so a crafted `{ "__proto__": … }` input can't
|
|
129
|
+
// reassign the returned dictionary's prototype, and the entry stays enumerable so `min`/`max` counts are correct.
|
|
130
|
+
const safeDictionary = Object.create(null);
|
|
128
131
|
const messages = [];
|
|
129
132
|
for (const [key, unsafeValue] of getDictionaryItems(unsafeDictionary)) {
|
|
130
133
|
try {
|