{"version":3,"file":"pathname.mjs","names":[],"sources":["../../src/middleware-dir/pathname.ts"],"sourcesContent":["/** Normalizes segments independently so malformed params cannot block static normalization. */\nexport function normalizePathname(pathname: string): string {\n  return pathname\n    .split('/')\n    .map((segment) => {\n      try {\n        // Re-encode each segment so escaped separators and encoding levels stay distinct.\n        return encodeURIComponent(decodeURIComponent(segment).normalize('NFC'));\n      } catch {\n        // Preserve malformed escape sequences without rejecting the request.\n        return segment.normalize('NFC');\n      }\n    })\n    .join('/');\n}\n\n/** Removes trailing slashes while keeping the root pathname distinct. */\nexport function stripTrailingSlashes(pathname: string): string {\n  return pathname.length > 1 ? pathname.replace(/\\/+$/, '') || '/' : pathname;\n}\n\n/** Applies the request pathname's trailing-slash style to a target path. */\nexport function applyTrailingSlash(\n  pathname: string,\n  targetPathname: string\n): string {\n  const sourceHasTrailingSlash = pathname.length > 1 && pathname.endsWith('/');\n  if (sourceHasTrailingSlash) {\n    return targetPathname === '/' || targetPathname.endsWith('/')\n      ? targetPathname\n      : `${targetPathname}/`;\n  }\n  return stripTrailingSlashes(targetPathname);\n}\n"],"mappings":";;AACA,SAAgB,kBAAkB,UAA0B;AAC1D,QAAO,SACJ,MAAM,IAAI,CACV,KAAK,YAAY;AAChB,MAAI;AAEF,UAAO,mBAAmB,mBAAmB,QAAQ,CAAC,UAAU,MAAM,CAAC;UACjE;AAEN,UAAO,QAAQ,UAAU,MAAM;;GAEjC,CACD,KAAK,IAAI;;;AAId,SAAgB,qBAAqB,UAA0B;AAC7D,QAAO,SAAS,SAAS,IAAI,SAAS,QAAQ,QAAQ,GAAG,IAAI,MAAM;;;AAIrE,SAAgB,mBACd,UACA,gBACQ;AAER,KAD+B,SAAS,SAAS,KAAK,SAAS,SAAS,IAAI,CAE1E,QAAO,mBAAmB,OAAO,eAAe,SAAS,IAAI,GACzD,iBACA,GAAG,eAAe;AAExB,QAAO,qBAAqB,eAAe"}