Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-145

Pattern matching is not working as expected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • Beta 9
    • Beta 8
    • None
    • None

      There is a bug in PathParamSegment at line 201:

      if (matcher.find(start))
      {

      To fix it you need to replace this line by:

      if (matcher.find(start) && matcher.start() == start)
      {

      Because of this bug the matching mechanism will fails in some situations.

      Let's say you have a resource:

      class MyResource {

      @GET
      @Path(".

      {service}

      ")
      return ServiceResource getService(@PathParam("service") String serviceName)

      { return ServiceFactory.newService(serviceName); }

      @GET
      @Path("

      {path}

      ")
      public MyResource getChild(@PathParam("path") String path)

      { return new MyResource(getChild(path)); }

      }

      And let's say you map a MyResource resource on the path: /repository/workspaces/ws
      Also we assume the 'ws' MyResource has child 'ws2' (which is a MyResource) and any MyResource object have a service named ".views"

      In this case the following URL will not be dispatched correctly:

      /repository/workspaces/ws/ws2/.views/content

      This is because the ".views" sub-resource will be found for "/repository/workspaces"
      but the matcher code is not checking if the ".views" resource is a direct child of "/repository/workspaces"
      So this can be fixed by simply adding a check like:
      if (matcher.find(start) && matcher.start() == start)
      instead of doing
      if (matcher.find(start))

      So,the "ws/ws2" segments will be skiped and their corresponding sub-resources will not be instantiated.

      More, this bug can be reproduced ponly with particular segment names.
      For example the following request will work:

      /repository/workspaces/ws/ws22/.views/content

      because of the length of ws22 segment ...

      This is because in the first case (when using 'ws2') the check
      if (path.charAt(start + matcher.group(0).length()) == '/')
      will return true - but it will return false for the second case.

            patriot1burke@gmail.com Bill Burke (Inactive)
            bstefanescu Bogdan Stefanescu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: