Mappings filter doesn't use modified `path` anymore

Enonic version: 7.8.3
OS: Linux

Hi,

I have a mapping to a filter, which seems to have broken in more recent versions of XP (7.8.x ?).

I have one content, that I want to split into many sub-pages. I use a filter to change a url from /mypath/skjema/side1 to /mypath?pageKey=side1

<?xml version="1.0" encoding="UTF-8"?>
<site>
  <mappings>
    <mapping filter="/filters/form-subpage.js" order="40">
      <pattern>.*/skjema/.*</pattern>
    </mapping>
  </mappings>
</site>
import { substringAfterLast, substringBefore } from "../lib/strings"

export function filter(req: XP.Request, next: XP.Controller): XP.Response {z
  return next({
    ...req,
    path: substringBefore(req.path, "/skjema/"),
    params: {
      ...(req.params ?? {}),
      pageKey: substringAfterLast(req.path, "/skjema/"),
    },
  })
}

This has stopped working with the following message, even if I change the path i pass into next().

(/filters/form-subpage.js) com.enonic.xp.web.WebException: Page [/mysite/mypath/skjema/about] not found

Can it be that next() doesn’t take the submitted path into account anymore?

– Tom

I don’t think it ever worked.

  • content gets resolved before filter is executed. But before the fix it was always some content (in your case it was content with path somesite/mypath ). After the fix, if path points to non-existent content - there will be no content resolved.

  • filters never supported chaining. There is an open issue for that.

This worked for us for many months, so I that is not correct.

The reason it “worked” is because the content exists under /mypath, and in XP before 7.8 /mypath/skjema/side1 would (incorrectly) resolve that content.

If you would change path from /mypath/skjema/side1 to /notmypath?pageKey=side1 you would see that content is still “mypath”.

I think @rymsha answered this well, and this topic can be closed.