Skip to content

Issue 46962: Fix decoding of paths containing encoded commas #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.17.1 - 2022-12-19
- Fix URI decoding for paths with encoded characters in container names

## 1.17.0 - 2022-12-15
- Add PrimaryStorage as a new STORAGE_TYPE equivalent to Freezer for room-temp storage

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@labkey/api",
"version": "1.17.0",
"version": "1.17.1",
"description": "JavaScript client API for LabKey Server",
"scripts": {
"build": "npm run build:dist && npm run build:docs",
Expand Down
6 changes: 5 additions & 1 deletion src/labkey/ActionURL.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('ActionURL', () => {
});

test('with context path', () => {
const contextPath = '/myContextPath';
let contextPath = '/myContextPath';
getServerContext().contextPath = contextPath;

// new style URL
Expand All @@ -110,6 +110,10 @@ describe('ActionURL', () => {
'pipeline-status',
'action'
);
contextPath ='/my, CommaContext';
getServerContext().contextPath = contextPath;
validatePath(`${contextPath}/1%2C%202/pro%2C%20ject-be%2C%20%2Cgin.view`, contextPath, '/1, 2', 'pro, ject', 'be, ,gin');
validatePath(`${contextPath}/1%2C%202%2C%203/project-begin.view`, contextPath, '/1, 2, 3', 'project', 'begin');

// old style URL
validatePath(`${contextPath}/project/home/begin.view`, contextPath, '/home', 'project', 'begin');
Expand Down
21 changes: 20 additions & 1 deletion src/labkey/ActionURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@ export interface ActionPath {
controller: string;
}

/**
* decodeURI chooses not to decode characters that are part of the URI syntax (; / ? : @ & = + $ , #).
* This can be problematic since we do encode these characters on the server side when they are part of the path.
* Here, we decode the subset of these encoded characters that can be part of a project name.
* @param path to be decoded.
* @return A new copy of the given path with all encoded characters decoded
*/
function fullyDecodeURIPath(path: string): string
{
return decodeURI(path)
.replace(/%2C/g, ",")
.replace(/%3B/g, ";")
.replace(/%40/g, "@")
.replace(/%26/g, "&")
.replace(/%3D/g, "=")
.replace(/%24/g, "$")
.replace(/%23/g, "#");
}

/**
* Parses a location pathname of a LabKey URL into its constituent parts (e.g. controller, action, etc).
* Defaults to the current location's pathname and context path. The parsed parts of the [[ActionPath]] are
Expand Down Expand Up @@ -343,7 +362,7 @@ export function getPathFromLocation(pathname?: string, contextPath?: string): Ac

return {
action: decodeURIComponent(action),
containerPath: decodeURI(path),
containerPath: fullyDecodeURIPath(path),
contextPath: decodeURIComponent(ctxPath),
controller: decodeURIComponent(controller),
};
Expand Down