Skip to content

Commit 5b91ae3

Browse files
committed
pass site data to url validator
1 parent 6e955fd commit 5b91ae3

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pass site data to URL validator. @danalvrz

packages/volto-iframe-block/src/components/Edit.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import clearSVG from '@plone/volto/icons/clear.svg';
77
import React, { useState, useEffect, useRef } from 'react';
88
import { defineMessages } from 'react-intl';
99
import { toast } from 'react-toastify';
10+
import { useSelector } from 'react-redux';
1011

1112
import {
1213
isValidUrl,
@@ -30,6 +31,7 @@ const IframeEdit = (props) => {
3031
const { data, intl } = props;
3132
const [url, setUrl] = useState('');
3233
const iframeRef = useRef(null);
34+
const siteData = useSelector((state) => state.site.data);
3335

3436
const onChangeUrl = ({ target }) => {
3537
setUrl(target.value);
@@ -40,7 +42,7 @@ const IframeEdit = (props) => {
4042
};
4143

4244
const onSubmitUrl = () => {
43-
if (isValidUrl(url)) {
45+
if (isValidUrl(url, siteData)) {
4446
props.onChangeBlock(props.block, {
4547
...props.data,
4648
src: url,

packages/volto-iframe-block/src/helpers/isValidUrl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export const toastError = defineMessages({
1717
},
1818
});
1919

20-
export function isValidUrl(url) {
20+
export function isValidUrl(props) {
2121
const patterns = config.blocks.blocksConfig.iframe.validUrls;
2222

2323
if (isEmpty(patterns)) {
2424
return true;
25-
} else if (patterns.some((pattern) => pattern.includes(url))) {
25+
} else if (patterns.some((pattern) => pattern.includes(props.url))) {
2626
return true;
2727
} else {
2828
return false;

0 commit comments

Comments
 (0)