env
- express@4.21.0
- node@18.19.0
- path-to-regexp@0.1.10 and path-to-regexp@0.1.11
see:
Code Analysis:
see:
step:
methods includes bind.
- Therefore,
app has a bind function.
- The
bind function can accept this, which is an object (path).
- However, in the
bind function, this._router.route(path) receives this object.
- This object is passed to
path-to-regexp.
- In
path-to-regexp v0.1.7, the object is converted to a string without causing an error.
- In
path-to-regexp v0.1.10, encountering an object can cause the program to crash.
- This is the reason for the program crash after the update.
The version that found the problem was 0.1.10, but this error was thrown in 0.1.11.
if (typeof path !== 'string') {
throw new TypeError('path must be a string, array of strings, or regular expression');
}
imgA:

imgB:

In imgA, httpolyglot passed an object, which was concatenated into a string in path-to-regexp 0.1.7, and the program had no errors. However, in later versions of path-to-regexp, my use case ran into errors because the object could not be handled "friendly".
If you decide to upgrade path-to-regexp, should you keep old programs compatible without causing them to crash? What is the right way to do it? Do you not handle the app passed in when bind?
env
see:
Code Analysis:
see:
express/lib/application.js
Line 489 in 7e562c6
step:
methodsincludesbind.apphas abindfunction.bindfunction can acceptthis, which is an object (path).bindfunction,this._router.route(path)receives this object.path-to-regexp.path-to-regexpv0.1.7, the object is converted to a string without causing an error.path-to-regexpv0.1.10, encountering an object can cause the program to crash.The version that found the problem was 0.1.10, but this error was thrown in 0.1.11.
imgA:
imgB:
In imgA, httpolyglot passed an object, which was concatenated into a string in path-to-regexp 0.1.7, and the program had no errors. However, in later versions of path-to-regexp, my use case ran into errors because the object could not be handled "friendly".
If you decide to upgrade path-to-regexp, should you keep old programs compatible without causing them to crash? What is the right way to do it? Do you not handle the app passed in when bind?