Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"mustache": "4.2.0",
"otpauth": "9.4.0",
"parse": "7.0.1",
"path-to-regexp": "6.3.0",
"path-to-regexp": "8.3.0",
"pg-monitor": "3.0.0",
"pg-promise": "12.2.0",
"pluralize": "8.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/cloud-code/Parse.Cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ const getRoute = parseClass => {
'@Config' : 'config',
}[parseClass] || 'classes';
if (parseClass === '@File') {
return `/${route}/:id?(.*)`;
return `/${route}{/*id}`;
}
if (parseClass === '@Config') {
return `/${route}`;
}
return `/${route}/${parseClass}/:id?(.*)`;
return `/${route}/${parseClass}{/*id}`;
};
/** @namespace
* @name Parse
Expand Down
33 changes: 28 additions & 5 deletions src/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ const handleRateLimit = async (req, res, next) => {
try {
await Promise.all(
rateLimits.map(async limit => {
const pathExp = new RegExp(limit.path);
const pathExp = limit.path.regexp || limit.path;
if (pathExp.test(req.url)) {
await limit.handler(req, res, err => {
if (err) {
Expand Down Expand Up @@ -561,10 +561,33 @@ export const addRateLimit = (route, config, cloud) => {
},
});
}
let transformPath = route.requestPath.split('/*').join('/(.*)');
if (transformPath === '*') {
transformPath = '(.*)';
}
// Transform wildcards to named parameters for path-to-regexp v8
// Only transform standalone * (not those already in named params like :id* or *id)
let transformPath = route.requestPath;
// Replace * that are not part of named parameter syntax
// Use a function to check if * is part of a named parameter
transformPath = transformPath.replace(/\*/g, (match, offset, string) => {
// Check if this * is part of a named parameter (e.g., :id*)
// Look backwards to find if there's a : before this * (without a / in between)
let isNamedParam = false;
for (let i = offset - 1; i >= 0; i--) {
if (string[i] === '/') {
break; // Found a /, so this * is not part of a named param
}
if (string[i] === ':') {
isNamedParam = true; // Found :, so this * is part of a named param
break;
}
}
// Check if * is followed by an identifier (like *id) - this is already a named wildcard
const nextChar = offset + 1 < string.length ? string[offset + 1] : null;
const isNamedWildcard = nextChar && /[a-zA-Z_$]/.test(nextChar);
// Only transform if it's not part of a named parameter and not already a named wildcard
if (!isNamedParam && !isNamedWildcard) {
return '*path';
}
return match; // Keep * if it's part of :param* or *id
});
config.rateLimits.push({
path: pathToRegexp(transformPath),
handler: rateLimit({
Expand Down
Loading