mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(api): strip query params on redirect (#58608)
This commit is contained in:
committed by
GitHub
parent
991f6a2f36
commit
436d27da52
@@ -165,6 +165,23 @@ describe('redirection', () => {
|
||||
expect(result).toEqual(expectedReturn);
|
||||
});
|
||||
|
||||
it('should strip off any query parameters from the referer', () => {
|
||||
const req = {
|
||||
headers: {
|
||||
referer: `https://www.freecodecamp.org/espanol/learn/rosetta-code/?query=param`
|
||||
}
|
||||
};
|
||||
|
||||
const expectedReturn = {
|
||||
origin: 'https://www.freecodecamp.org',
|
||||
pathPrefix: 'espanol',
|
||||
returnTo: 'https://www.freecodecamp.org/espanol/learn/rosetta-code/'
|
||||
};
|
||||
|
||||
const result = getRedirectParams(req);
|
||||
expect(result).toEqual(expectedReturn);
|
||||
});
|
||||
|
||||
it('should use HOME_LOCATION with missing referer', () => {
|
||||
const req = {
|
||||
headers: {}
|
||||
|
||||
@@ -113,7 +113,12 @@ function getParamsFromUrl(
|
||||
// if this is not one of the client languages, validation will convert
|
||||
// this to '' before it is used.
|
||||
const pathPrefix = returnUrl.pathname.split('/')[1] ?? '';
|
||||
return normalize({ returnTo: returnUrl.href, origin, pathPrefix });
|
||||
return normalize({
|
||||
// strip off any query parameters
|
||||
returnTo: returnUrl.origin + returnUrl.pathname,
|
||||
origin,
|
||||
pathPrefix
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user