Skip to content

Commit 4c1093e

Browse files
authored
refactor: Upgrade path-to-regexp from 0.1.7 to 6.2.1 (#8558)
1 parent 00c362d commit 4c1093e

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

package-lock.json

+17-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"mongodb": "4.10.0",
5050
"mustache": "4.2.0",
5151
"parse": "4.0.1",
52-
"path-to-regexp": "0.1.7",
52+
"path-to-regexp": "6.2.1",
5353
"pg-monitor": "2.0.0",
5454
"pg-promise": "11.3.0",
5555
"pluralize": "8.0.0",

src/cloud-code/Parse.Cloud.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ const getRoute = parseClass => {
8282
'@File': 'files',
8383
}[parseClass] || 'classes';
8484
if (parseClass === '@File') {
85-
return `/${route}/:id?*`;
85+
return `/${route}/:id?(.*)`;
8686
}
87-
return `/${route}/${parseClass}/:id?*`;
87+
return `/${route}/${parseClass}/:id?(.*)`;
8888
};
8989
/** @namespace
9090
* @name Parse

src/middlewares.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import MongoStorageAdapter from './Adapters/Storage/Mongo/MongoStorageAdapter';
99
import PostgresStorageAdapter from './Adapters/Storage/Postgres/PostgresStorageAdapter';
1010
import rateLimit from 'express-rate-limit';
1111
import { RateLimitOptions } from './Options/Definitions';
12-
import pathToRegexp from 'path-to-regexp';
12+
import { pathToRegexp } from 'path-to-regexp';
1313
import ipRangeCheck from 'ip-range-check';
1414
import RedisStore from 'rate-limit-redis';
1515
import { createClient } from 'redis';
@@ -512,8 +512,12 @@ export const addRateLimit = (route, config, cloud) => {
512512
},
513513
});
514514
}
515+
let transformPath = route.requestPath.replaceAll('/*', '/(.*)');
516+
if (transformPath === '*') {
517+
transformPath = '(.*)';
518+
}
515519
config.rateLimits.push({
516-
path: pathToRegexp(route.requestPath),
520+
path: pathToRegexp(transformPath),
517521
handler: rateLimit({
518522
windowMs: route.requestTimeWindow,
519523
max: route.requestCount,

0 commit comments

Comments
 (0)