@emeryld/rrroutes-server 2.5.0 → 2.5.1

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/dist/index.js CHANGED
@@ -96,6 +96,29 @@ var sanitizeValue = (value, options, depth, seen, req, target, path) => {
96
96
  seen.delete(value);
97
97
  return applyCustomSanitizer(objectTarget, options, context);
98
98
  };
99
+ var findPropertyDescriptor = (source, key) => {
100
+ let cursor = source;
101
+ while (cursor) {
102
+ const descriptor = Object.getOwnPropertyDescriptor(cursor, key);
103
+ if (descriptor) return descriptor;
104
+ cursor = Object.getPrototypeOf(cursor);
105
+ }
106
+ return void 0;
107
+ };
108
+ var setRequestQuery = (req, value) => {
109
+ const queryDescriptor = findPropertyDescriptor(req, "query");
110
+ if (!queryDescriptor || queryDescriptor.writable || queryDescriptor.set) {
111
+ ;
112
+ req.query = value;
113
+ return;
114
+ }
115
+ Object.defineProperty(req, "query", {
116
+ configurable: true,
117
+ enumerable: true,
118
+ writable: true,
119
+ value
120
+ });
121
+ };
99
122
  var createRequestSanitizationMiddleware = (options = {}) => {
100
123
  const normalized = normalizeOptions(options);
101
124
  return (req, _res, next) => {
@@ -111,16 +134,20 @@ var createRequestSanitizationMiddleware = (options = {}) => {
111
134
  []
112
135
  );
113
136
  }
114
- if (normalized.targets.has("query") && req.query) {
115
- req.query = sanitizeValue(
116
- req.query,
117
- normalized,
118
- 0,
119
- /* @__PURE__ */ new WeakSet(),
120
- req,
121
- "query",
122
- []
123
- );
137
+ if (normalized.targets.has("query")) {
138
+ const query = req.query;
139
+ if (query) {
140
+ const sanitizedQuery = sanitizeValue(
141
+ query,
142
+ normalized,
143
+ 0,
144
+ /* @__PURE__ */ new WeakSet(),
145
+ req,
146
+ "query",
147
+ []
148
+ );
149
+ setRequestQuery(req, sanitizedQuery);
150
+ }
124
151
  }
125
152
  if (normalized.targets.has("body") && req.body !== void 0) {
126
153
  req.body = sanitizeValue(