Skip to content

Commit 8a6a501

Browse files
Issue 46962: Fix decoding of paths containing encoded commas (#140)
1 parent ee4987f commit 8a6a501

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.17.1 - 2022-12-19
2+
- Fix URI decoding for paths with encoded characters in container names
3+
14
## 1.17.0 - 2022-12-15
25
- Add PrimaryStorage as a new STORAGE_TYPE equivalent to Freezer for room-temp storage
36

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@labkey/api",
3-
"version": "1.17.0",
3+
"version": "1.17.1",
44
"description": "JavaScript client API for LabKey Server",
55
"scripts": {
66
"build": "npm run build:dist && npm run build:docs",

src/labkey/ActionURL.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('ActionURL', () => {
9797
});
9898

9999
test('with context path', () => {
100-
const contextPath = '/myContextPath';
100+
let contextPath = '/myContextPath';
101101
getServerContext().contextPath = contextPath;
102102

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

114118
// old style URL
115119
validatePath(`${contextPath}/project/home/begin.view`, contextPath, '/home', 'project', 'begin');

src/labkey/ActionURL.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,25 @@ export interface ActionPath {
273273
controller: string;
274274
}
275275

276+
/**
277+
* decodeURI chooses not to decode characters that are part of the URI syntax (; / ? : @ & = + $ , #).
278+
* This can be problematic since we do encode these characters on the server side when they are part of the path.
279+
* Here, we decode the subset of these encoded characters that can be part of a project name.
280+
* @param path to be decoded.
281+
* @return A new copy of the given path with all encoded characters decoded
282+
*/
283+
function fullyDecodeURIPath(path: string): string
284+
{
285+
return decodeURI(path)
286+
.replace(/%2C/g, ",")
287+
.replace(/%3B/g, ";")
288+
.replace(/%40/g, "@")
289+
.replace(/%26/g, "&")
290+
.replace(/%3D/g, "=")
291+
.replace(/%24/g, "$")
292+
.replace(/%23/g, "#");
293+
}
294+
276295
/**
277296
* Parses a location pathname of a LabKey URL into its constituent parts (e.g. controller, action, etc).
278297
* Defaults to the current location's pathname and context path. The parsed parts of the [[ActionPath]] are
@@ -343,7 +362,7 @@ export function getPathFromLocation(pathname?: string, contextPath?: string): Ac
343362

344363
return {
345364
action: decodeURIComponent(action),
346-
containerPath: decodeURI(path),
365+
containerPath: fullyDecodeURIPath(path),
347366
contextPath: decodeURIComponent(ctxPath),
348367
controller: decodeURIComponent(controller),
349368
};

0 commit comments

Comments
 (0)