From 96970cf6075a5b02e8c5b25acfc18eed02cde010 Mon Sep 17 00:00:00 2001
From: Ejaz Ahmad <86868918+jajjibhai008@users.noreply.github.com>
Date: Fri, 25 Oct 2024 17:24:53 +0500
Subject: [PATCH] refactor: improve the sanitization for expiration modal
(#1213)
---
.../expired-subscription-modal/index.jsx | 31 +++++++------------
.../tests/ExpiredSubscriptionModal.test.jsx | 16 +++++-----
2 files changed, 18 insertions(+), 29 deletions(-)
diff --git a/src/components/expired-subscription-modal/index.jsx b/src/components/expired-subscription-modal/index.jsx
index ff8dbedc30..5e69f184f4 100644
--- a/src/components/expired-subscription-modal/index.jsx
+++ b/src/components/expired-subscription-modal/index.jsx
@@ -1,6 +1,7 @@
import {
useToggle, AlertModal, Button, ActionRow,
} from '@openedx/paragon';
+import DOMPurify from 'dompurify';
import { useSubscriptions } from '../app/data';
const ExpiredSubscriptionModal = () => {
@@ -9,37 +10,27 @@ const ExpiredSubscriptionModal = () => {
if (!customerAgreement?.hasCustomLicenseExpirationMessaging) {
return null;
}
- const onClickHandler = () => {
- let url = customerAgreement?.urlForButtonInModal;
-
- if (url) {
- // Check if the URL starts with 'http://' or 'https://'
- if (!url.startsWith('http://') && !url.startsWith('https://')) {
- // Prepend 'https://' if the URL is missing the protocol
- url = `https://${url}`;
- }
-
- // Navigate to the full URL
- window.open(url, '_blank'); // Opening in a new tab
- }
- };
return (
{customerAgreement.modalHeaderText}
}
isOpen={isOpen}
isBlocking
footerNode={(
Your subscription has expired.
', - urlForButtonInModal: 'example.com', + urlForButtonInModal: 'https://example.com', }, }, }); - // Mock window.open - const windowOpenSpy = jest.spyOn(window, 'open').mockImplementation(() => {}); - // Render the component renderWithRouter(