path-to-regexp icon indicating copy to clipboard operation
path-to-regexp copied to clipboard

[DO NOT MERGE] global route match bug demo

Open zone117x opened this issue 4 years ago • 1 comments

[Do not merge] Only opening a PR here for the CI tests to demostrate the bug.

Global route match syntax cause a parsing error.

For example, when using the route:

  app.get('/test/*', (req, res) => {
    res.sendStatus(200);
  });

The parsing error is thrown:

  ● path-to-regexp › rules › '/test/*' › encountered a declaration exception

    TypeError: Unexpected MODIFIER at 6, expected END

      155 |     if (value !== undefined) return value;
      156 |     const { type: nextType, index } = tokens[i];
    > 157 |     throw new TypeError(`Unexpected ${nextType} at ${index}, expected ${type}`);
          |           ^
      158 |   };
      159 | 
      160 |   const consumeText = (): string => {

      at mustConsume (src/index.ts:157:11)
      at parse (src/index.ts:228:5)
      at stringToRegexp (src/index.ts:495:25)
      at Object.pathToRegexp (src/index.ts:617:10)
      at Suite.<anonymous> (src/index.spec.ts:2804:33)
      at src/index.spec.ts:2802:7
          at Array.forEach (<anonymous>)
      at Suite.<anonymous> (src/index.spec.ts:2799:11)
      at Suite.<anonymous> (src/index.spec.ts:2798:3)
      at Object.<anonymous> (src/index.spec.ts:2705:1)

See Express documentation for global/wildcard route definitions here: https://expressjs.com/en/4x/api.html#router.methods

zone117x avatar Mar 16 '21 16:03 zone117x

Coverage Status

Coverage remained the same at 100.0% when pulling b5a92ac6d7da1bca2058eba160893853147412f3 on zone117x:demo/global-prefix-route-bug into b39edd433c173257062883f58867feecee660fd4 on pillarjs:master.

coveralls avatar Mar 16 '21 16:03 coveralls