Area restrita - Questionario
This commit is contained in:
+71
-41
@@ -6,7 +6,7 @@ export { BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta, NavLi
|
||||
import { serialize, parse } from 'cookie';
|
||||
|
||||
/**
|
||||
* react-router v7.14.0
|
||||
* react-router v7.17.0
|
||||
*
|
||||
* Copyright (c) Remix Software Inc.
|
||||
*
|
||||
@@ -40,7 +40,7 @@ function warning(cond, message) {
|
||||
function createKey() {
|
||||
return Math.random().toString(36).substring(2, 10);
|
||||
}
|
||||
function createLocation(current, to, state = null, key, unstable_mask) {
|
||||
function createLocation(current, to, state = null, key, mask) {
|
||||
let location = {
|
||||
pathname: typeof current === "string" ? current : current.pathname,
|
||||
search: "",
|
||||
@@ -52,7 +52,7 @@ function createLocation(current, to, state = null, key, unstable_mask) {
|
||||
// But that's a pretty big refactor to the current test suite so going to
|
||||
// keep as is for the time being and just let any incoming keys take precedence
|
||||
key: to && to.key || key || createKey(),
|
||||
unstable_mask
|
||||
mask
|
||||
};
|
||||
return location;
|
||||
}
|
||||
@@ -232,11 +232,11 @@ async function recurseRight(impls, info, handler, index) {
|
||||
};
|
||||
}
|
||||
function getHandlerInfo(args) {
|
||||
let { request, context, params, unstable_pattern } = args;
|
||||
let { request, context, params, pattern } = args;
|
||||
return {
|
||||
request: getReadonlyRequest(request),
|
||||
params: { ...params },
|
||||
unstable_pattern,
|
||||
pattern,
|
||||
context: getReadonlyContext(context)
|
||||
};
|
||||
}
|
||||
@@ -406,17 +406,16 @@ function mergeRouteUpdates(route, updates) {
|
||||
function matchRoutes(routes, locationArg, basename = "/") {
|
||||
return matchRoutesImpl(routes, locationArg, basename, false);
|
||||
}
|
||||
function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
|
||||
function matchRoutesImpl(routes, locationArg, basename, allowPartial, precomputedBranches) {
|
||||
let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
||||
let pathname = stripBasename(location.pathname || "/", basename);
|
||||
if (pathname == null) {
|
||||
return null;
|
||||
}
|
||||
let branches = flattenRoutes(routes);
|
||||
rankRouteBranches(branches);
|
||||
let branches = precomputedBranches ?? flattenAndRankRoutes(routes);
|
||||
let matches = null;
|
||||
let decoded = decodePath(pathname);
|
||||
for (let i = 0; matches == null && i < branches.length; ++i) {
|
||||
let decoded = decodePath(pathname);
|
||||
matches = matchRouteBranch(
|
||||
branches[i],
|
||||
decoded,
|
||||
@@ -436,6 +435,11 @@ function convertRouteMatchToUiMatch(match, loaderData) {
|
||||
handle: route.handle
|
||||
};
|
||||
}
|
||||
function flattenAndRankRoutes(routes) {
|
||||
let branches = flattenRoutes(routes);
|
||||
rankRouteBranches(branches);
|
||||
return branches;
|
||||
}
|
||||
function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "", _hasParentOptionalSegments = false) {
|
||||
let flattenRoute = (route, index, hasParentOptionalSegments = _hasParentOptionalSegments, relativePath) => {
|
||||
let meta = {
|
||||
@@ -707,7 +711,7 @@ function resolvePath(to, fromPathname = "/") {
|
||||
} = typeof to === "string" ? parsePath(to) : to;
|
||||
let pathname;
|
||||
if (toPathname) {
|
||||
toPathname = toPathname.replace(/\/\/+/g, "/");
|
||||
toPathname = removeDoubleSlashes(toPathname);
|
||||
if (toPathname.startsWith("/")) {
|
||||
pathname = resolvePathname(toPathname.substring(1), "/");
|
||||
} else {
|
||||
@@ -723,7 +727,7 @@ function resolvePath(to, fromPathname = "/") {
|
||||
};
|
||||
}
|
||||
function resolvePathname(relativePath, fromPathname) {
|
||||
let segments = fromPathname.replace(/\/+$/, "").split("/");
|
||||
let segments = removeTrailingSlash(fromPathname).split("/");
|
||||
let relativeSegments = relativePath.split("/");
|
||||
relativeSegments.forEach((segment) => {
|
||||
if (segment === "..") {
|
||||
@@ -794,8 +798,10 @@ function resolveTo(toArg, routePathnames, locationPathname, isPathRelative = fal
|
||||
}
|
||||
return path;
|
||||
}
|
||||
var joinPaths = (paths) => paths.join("/").replace(/\/\/+/g, "/");
|
||||
var normalizePathname = (pathname) => pathname.replace(/\/+$/, "").replace(/^\/*/, "/");
|
||||
var removeDoubleSlashes = (path) => path.replace(/\/\/+/g, "/");
|
||||
var joinPaths = (paths) => removeDoubleSlashes(paths.join("/"));
|
||||
var removeTrailingSlash = (path) => path.replace(/\/+$/, "");
|
||||
var normalizePathname = (pathname) => removeTrailingSlash(pathname).replace(/^\/*/, "/");
|
||||
var normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
|
||||
var normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
|
||||
var DataWithResponseInit = class {
|
||||
@@ -849,7 +855,8 @@ function isRouteErrorResponse(error) {
|
||||
return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
|
||||
}
|
||||
function getRoutePattern(matches) {
|
||||
return matches.map((m) => m.route.path).filter(Boolean).join("/").replace(/\/\/*/g, "/") || "/";
|
||||
let parts = matches.map((m) => m.route.path).filter(Boolean);
|
||||
return joinPaths(parts) || "/";
|
||||
}
|
||||
|
||||
// lib/router/router.ts
|
||||
@@ -882,11 +889,10 @@ function createStaticHandler(routes, opts) {
|
||||
let _mapRouteProperties = opts?.mapRouteProperties || defaultMapRouteProperties;
|
||||
let mapRouteProperties = _mapRouteProperties;
|
||||
({
|
||||
// unused in static handler
|
||||
...opts?.future
|
||||
});
|
||||
if (opts?.unstable_instrumentations) {
|
||||
let instrumentations = opts.unstable_instrumentations;
|
||||
if (opts?.instrumentations) {
|
||||
let instrumentations = opts.instrumentations;
|
||||
mapRouteProperties = (route) => {
|
||||
return {
|
||||
..._mapRouteProperties(route),
|
||||
@@ -903,6 +909,7 @@ function createStaticHandler(routes, opts) {
|
||||
void 0,
|
||||
manifest
|
||||
);
|
||||
let routeBranches = flattenAndRankRoutes(dataRoutes);
|
||||
async function query(request, {
|
||||
requestContext,
|
||||
filterMatchesToLoad,
|
||||
@@ -910,12 +917,23 @@ function createStaticHandler(routes, opts) {
|
||||
skipRevalidation,
|
||||
dataStrategy,
|
||||
generateMiddlewareResponse,
|
||||
unstable_normalizePath
|
||||
normalizePath
|
||||
} = {}) {
|
||||
let normalizePath = unstable_normalizePath || defaultNormalizePath;
|
||||
let normalizePathImpl = normalizePath || defaultNormalizePath;
|
||||
let method = request.method;
|
||||
let location = createLocation("", normalizePath(request), null, "default");
|
||||
let matches = matchRoutes(dataRoutes, location, basename);
|
||||
let location = createLocation(
|
||||
"",
|
||||
normalizePathImpl(request),
|
||||
null,
|
||||
"default"
|
||||
);
|
||||
let matches = matchRoutesImpl(
|
||||
dataRoutes,
|
||||
location,
|
||||
basename,
|
||||
false,
|
||||
routeBranches
|
||||
);
|
||||
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
||||
if (!isValidMethod(method) && method !== "HEAD") {
|
||||
let error = getInternalRouterError(405, { method });
|
||||
@@ -967,8 +985,8 @@ function createStaticHandler(routes, opts) {
|
||||
let response = await runServerMiddlewarePipeline(
|
||||
{
|
||||
request,
|
||||
unstable_url: createDataFunctionUrl(request, location),
|
||||
unstable_pattern: getRoutePattern(matches),
|
||||
url: createDataFunctionUrl(request, location),
|
||||
pattern: getRoutePattern(matches),
|
||||
matches,
|
||||
params: matches[0].params,
|
||||
// If we're calling middleware then it must be enabled so we can cast
|
||||
@@ -1085,12 +1103,23 @@ function createStaticHandler(routes, opts) {
|
||||
requestContext,
|
||||
dataStrategy,
|
||||
generateMiddlewareResponse,
|
||||
unstable_normalizePath
|
||||
normalizePath
|
||||
} = {}) {
|
||||
let normalizePath = unstable_normalizePath || defaultNormalizePath;
|
||||
let normalizePathImpl = normalizePath || defaultNormalizePath;
|
||||
let method = request.method;
|
||||
let location = createLocation("", normalizePath(request), null, "default");
|
||||
let matches = matchRoutes(dataRoutes, location, basename);
|
||||
let location = createLocation(
|
||||
"",
|
||||
normalizePathImpl(request),
|
||||
null,
|
||||
"default"
|
||||
);
|
||||
let matches = matchRoutesImpl(
|
||||
dataRoutes,
|
||||
location,
|
||||
basename,
|
||||
false,
|
||||
routeBranches
|
||||
);
|
||||
requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
||||
if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") {
|
||||
throw getInternalRouterError(405, { method });
|
||||
@@ -1115,8 +1144,8 @@ function createStaticHandler(routes, opts) {
|
||||
let response = await runServerMiddlewarePipeline(
|
||||
{
|
||||
request,
|
||||
unstable_url: createDataFunctionUrl(request, location),
|
||||
unstable_pattern: getRoutePattern(matches),
|
||||
url: createDataFunctionUrl(request, location),
|
||||
pattern: getRoutePattern(matches),
|
||||
matches,
|
||||
params: matches[0].params,
|
||||
// If we're calling middleware then it must be enabled so we can cast
|
||||
@@ -1500,6 +1529,7 @@ function createStaticHandler(routes, opts) {
|
||||
}
|
||||
return {
|
||||
dataRoutes,
|
||||
_internalRouteBranches: routeBranches,
|
||||
query,
|
||||
queryRoute
|
||||
};
|
||||
@@ -1851,7 +1881,7 @@ function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request,
|
||||
handler: lazyRoutePromises.lazyHandlerPromise
|
||||
};
|
||||
}
|
||||
function getDataStrategyMatch(mapRouteProperties, manifest, request, path, unstable_pattern, match, lazyRoutePropertiesToSkip, scopedContext, shouldLoad, shouldRevalidateArgs = null, callSiteDefaultShouldRevalidate) {
|
||||
function getDataStrategyMatch(mapRouteProperties, manifest, request, path, pattern, match, lazyRoutePropertiesToSkip, scopedContext, shouldLoad, shouldRevalidateArgs = null, callSiteDefaultShouldRevalidate) {
|
||||
let isUsingNewApi = false;
|
||||
let _lazyPromises = getDataStrategyMatchLazyPromises(
|
||||
mapRouteProperties,
|
||||
@@ -1886,7 +1916,7 @@ function getDataStrategyMatch(mapRouteProperties, manifest, request, path, unsta
|
||||
return callLoaderOrAction({
|
||||
request,
|
||||
path,
|
||||
unstable_pattern,
|
||||
pattern,
|
||||
match,
|
||||
lazyHandlerPromise: _lazyPromises?.handler,
|
||||
lazyRoutePromise: _lazyPromises?.route,
|
||||
@@ -1936,8 +1966,8 @@ async function callDataStrategyImpl(dataStrategyImpl, request, path, matches, fe
|
||||
}
|
||||
let dataStrategyArgs = {
|
||||
request,
|
||||
unstable_url: createDataFunctionUrl(request, path),
|
||||
unstable_pattern: getRoutePattern(matches),
|
||||
url: createDataFunctionUrl(request, path),
|
||||
pattern: getRoutePattern(matches),
|
||||
params: matches[0].params,
|
||||
context: scopedContext,
|
||||
matches
|
||||
@@ -1966,7 +1996,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, path, matches, fe
|
||||
async function callLoaderOrAction({
|
||||
request,
|
||||
path,
|
||||
unstable_pattern,
|
||||
pattern,
|
||||
match,
|
||||
lazyHandlerPromise,
|
||||
lazyRoutePromise,
|
||||
@@ -1993,8 +2023,8 @@ async function callLoaderOrAction({
|
||||
return handler(
|
||||
{
|
||||
request,
|
||||
unstable_url: createDataFunctionUrl(request, path),
|
||||
unstable_pattern,
|
||||
url: createDataFunctionUrl(request, path),
|
||||
pattern,
|
||||
params: match.params,
|
||||
context: scopedContext
|
||||
},
|
||||
@@ -2873,7 +2903,7 @@ async function generateResourceResponse(request, routes, basename, routeId, requ
|
||||
return generateErrorResponse(error);
|
||||
}
|
||||
},
|
||||
unstable_normalizePath: (r) => getNormalizedPath(r, basename, null)
|
||||
normalizePath: (r) => getNormalizedPath(r, basename, null)
|
||||
});
|
||||
return response;
|
||||
} catch (error) {
|
||||
@@ -2929,12 +2959,12 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
|
||||
skipLoaderErrorBubbling: isDataRequest,
|
||||
skipRevalidation: isSubmission,
|
||||
...routeIdsToLoad ? { filterMatchesToLoad: (m) => routeIdsToLoad.includes(m.route.id) } : {},
|
||||
unstable_normalizePath: (r) => getNormalizedPath(r, basename),
|
||||
normalizePath: (r) => getNormalizedPath(r, basename),
|
||||
async generateMiddlewareResponse(query) {
|
||||
let formState;
|
||||
let skipRevalidation = false;
|
||||
let potentialCSRFAttackError;
|
||||
if (request.method === "POST") {
|
||||
if (isMutationMethod(request.method)) {
|
||||
try {
|
||||
throwIfPotentialCSRFAttack(request.headers, allowedActionOrigins);
|
||||
ctx.runningAction = true;
|
||||
@@ -3442,7 +3472,7 @@ var unsign = async (cookie, secret) => {
|
||||
let signature = byteStringToUint8Array(atob(hash));
|
||||
let valid = await crypto.subtle.verify("HMAC", key, signature, data2);
|
||||
return valid ? value : false;
|
||||
} catch (error) {
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -3543,7 +3573,7 @@ function encodeData(value) {
|
||||
function decodeData(value) {
|
||||
try {
|
||||
return JSON.parse(decodeURIComponent(myEscape(atob(value))));
|
||||
} catch (error) {
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user