Skip to content
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

fix object metadata section crash due to un escaped characters #2928

Merged
merged 1 commit into from
Jul 7, 2023
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
9 changes: 9 additions & 0 deletions portal-ui/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,12 @@ export const replaceUnicodeChar = (inputString: string): string => {
let unicodeChar = "\u202E";
return inputString.split(unicodeChar).join("<�202e>");
};

// unescaped characters might throw error like '%'
export const safeDecodeURIComponent = (value: any) => {
try {
return decodeURIComponent(value);
} catch (err) {
return value;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
detailsPanel,
spacingUtils,
} from "../../../../Common/FormComponents/common/styleLibrary";
import { safeDecodeURIComponent } from "../../../../../../common/utils";

interface IObjectMetadata {
metaData: any;
Expand All @@ -40,6 +41,12 @@ const styles = (theme: Theme) =>
...detailsPanel,
});

const itemRendererFn = (element: any) => {
return Array.isArray(element)
? element.map(safeDecodeURIComponent).join(", ")
: safeDecodeURIComponent(element);
};

const ObjectMetaData = ({
metaData,
classes,
Expand All @@ -51,10 +58,7 @@ const ObjectMetaData = ({
return (
<Fragment>
{metaKeys.map((element: string, index: number) => {
const renderItem = Array.isArray(metaData[element])
? metaData[element].map(decodeURIComponent).join(", ")
: decodeURIComponent(metaData[element]);

const renderItem = itemRendererFn(metaData[element]);
return (
<Box
className={classes.metadataLinear}
Expand Down Expand Up @@ -94,10 +98,7 @@ const ObjectMetaData = ({
<Table className={classes.table} aria-label="simple table">
<TableBody>
{metaKeys.map((element: string, index: number) => {
const renderItem = Array.isArray(metaData[element])
? metaData[element].map(decodeURIComponent).join(", ")
: decodeURIComponent(metaData[element]);

const renderItem = itemRendererFn(metaData[element]);
return (
<TableRow key={`tRow-${index.toString()}`}>
<TableCell
Expand Down