Skip to content

fix: Not fully compatible with path-to-regexp@0.1.10, causing program errors #5999

@wll8

Description

@wll8

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:

image

imgB:

image

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions