Skip to content

Commit 23e3d4d

Browse files
fix(ui): Apply url encode and decode to a ProcessURL. Fixes argoproj#9791 (argoproj#9912)
1 parent d612d5d commit 23e3d4d

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

ui/src/app/shared/components/links.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ describe('process URL', () => {
1111
expect(ProcessURL('https://logging?from=${status.startedAt}&to=${status.finishedAt}', object)).toBe('https://logging?from=2021-01-01T10:30:00Z&to=2021-01-01T10:30:00Z');
1212
});
1313

14+
test('url encoded string', () => {
15+
const object = {
16+
metadata: {
17+
name: 'test'
18+
},
19+
status: {
20+
startedAt: '2021-01-01T10:30:00Z'
21+
}
22+
};
23+
expect(ProcessURL('https://logging/$%7Bmetadata.name%7D', object)).toBe('https://logging/test');
24+
});
25+
1426
test('epoch timestamp', () => {
1527
const object = {
1628
status: {

ui/src/app/shared/components/links.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@ const addEpochTimestamp = (jsonObject: {metadata: ObjectMeta; workflow?: Workflo
2222
};
2323

2424
export const ProcessURL = (url: string, jsonObject: any) => {
25+
/* decode url string to apply templating */
26+
const decodedUrl = decodeURI(url);
2527
addEpochTimestamp(jsonObject);
2628
/* replace ${} from input url with corresponding elements from object
2729
return null if element is not found*/
28-
return url.replace(/\${[^}]*}/g, x => {
29-
const res = x
30-
.replace(/[${}]+/g, '')
31-
.split('.')
32-
.reduce((p: any, c: string) => (p && p[c]) || null, jsonObject);
33-
return res;
34-
});
30+
return encodeURI(
31+
decodedUrl.replace(/\${[^}]*}/g, x => {
32+
const res = x
33+
.replace(/[${}]+/g, '')
34+
.split('.')
35+
.reduce((p: any, c: string) => (p && p[c]) || null, jsonObject);
36+
return res;
37+
})
38+
);
3539
};
3640

3741
export const Links = ({scope, object, button}: {scope: string; object: {metadata: ObjectMeta; workflow?: Workflow; status?: any}; button?: boolean}) => {
@@ -47,7 +51,7 @@ export const Links = ({scope, object, button}: {scope: string; object: {metadata
4751
}, []);
4852

4953
const formatUrl = (url: string) => {
50-
return encodeURI(ProcessURL(decodeURI(url), object));
54+
return ProcessURL(url, object);
5155
};
5256

5357
const openLink = (url: string) => {

0 commit comments

Comments
 (0)