pillarjs / path-to-regexp

Turn a path string such as `/user/:name` into a regular expression

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Erroneous test result.

Lord-Kamina opened this issue · comments

In master, you have the following:

[
    "\\/:pre?baz",
    undefined,
    [
      "/",
      {
        name: "pre",
        prefix: "",
        suffix: "",
        modifier: "?",
        pattern: "[^\\/#\\?]+?",
      },
      "baz",
    ],
    [
      ["/foobaz", ["/foobaz", "foo"]],
      ["/baz", ["/baz", undefined]],
    ]

But this is wrong. In reality, /baz would not match because options.start defaults to true.

I'm not entirely sure but I think the erroneous test result might be related to an incorrect tokenization in the test definition. With the code in master, the tokens actually look like the following:

[
    "\\/:pre?baz",
    undefined,
    [
-      "/",
      {
        name: "pre",
-      prefix: "",
+      prefix: "/",
        suffix: "",
        modifier: "?",
        pattern: "[^\\/#\\?]+?",
      },
      "baz",
    ],
    [
      ["/foobaz", ["/foobaz", "foo"]],
      ["/baz", ["/baz", undefined]],
    ]

The code on master is passing the test. I have it passing locally too. I’m not sure what you’re referring to when you say the “code on master” has a different result.

I'm finding it hard to discuss "in reality" here, because in reality these tests pass and /baz does match. Also, you're mentioning two things:

In reality, /baz would not match because options.start defaults to true.

In reality it does match and that's a code functionality of this library, to match this code.

With the code in master, the tokens actually look like the following

Are you saying, that in master, with zero code modifications, the test suite is failing? Can you share something to confirm this?

Jesus ignore me; I was very tired.

What I thought was happening was parse() returned a different value than what the test file actually registered (for me, both running your code as well as the ported version I was getting the same output, two tokens, one of them with a prefix) but I just realized I hadn't escaped the / in my route. Ignore this.