Skip to content

Commit 6c55fcb

Browse files
committed
Add tests for invalid embed codes and URLs
This also adds a check that the host of the URL includes OpenTable
1 parent 66455cb commit 6c55fcb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

extensions/blocks/opentable/test/utils.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { getAttributesFromEmbedCode } from '../utils';
99

1010
const widgetEmbedCode = "<script type='text/javascript' src='//www.opentable.com/widget/reservation/loader?rid=1&type=standard&theme=standard&iframe=true&domain=com&lang=en-US&newtab=false&ot_source=Restaurant%20website'></script>";
1111

12+
const invalidEmbedCode = "<script type='text/javascript' src='https://www.widgets-r-us.com/widget/widgetygoddness?rid=1&type=standard&theme=standard&iframe=true&domain=com&lang=en-US&newtab=false&ot_source=Restaurant%20website'></script>";
13+
1214
const marketingUrl = "https://www.opentable.com/vongs-thai-kitchen-reservations-chicago?restref=1&lang=en-US&ot_source=Restaurant%20website";
1315

1416
const customUrl1 = "https://www.opentable.com/restref/client/?restref=412810&lang=en-US&ot_source=Restaurant%20website&corrid=e413926b-0352-46d6-a8d8-d1d525932310";
@@ -17,6 +19,8 @@ const customUrl2 = "https://www.opentable.com/restref/client/?restref=1&lang=es-
1719

1820
const customUrl3 = "https://www.opentable.com/restref/client/?rid=1&corrid=010a3136-569e-42a5-a381-e111887b4cf5";
1921

22+
const invalidUrl = "https://www.widgets-r-us.com/widget/widgetygoddness?rid=1&type=standard&theme=standard&iframe=true&domain=com&lang=en-US&newtab=false&ot_source=Restaurant%20website";
23+
2024
describe( 'getAttributesFromEmbedCode', () => {
2125
test( 'Widget embed code', () => {
2226
expect(
@@ -75,4 +79,16 @@ describe( 'getAttributesFromEmbedCode', () => {
7579
}
7680
);
7781
} );
82+
83+
test( 'Invaild Embed Code', () => {
84+
expect(
85+
getAttributesFromEmbedCode( invalidEmbedCode )
86+
).toBeUndefined();
87+
} );
88+
89+
test( 'Invaild URL', () => {
90+
expect(
91+
getAttributesFromEmbedCode( invalidUrl )
92+
).toBeUndefined();
93+
} );
7894
} );

extensions/blocks/opentable/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const getAttributesFromUrl = url => {
1010
src = new URL( 'http:' + url );
1111
}
1212

13-
if ( ! src.search ) {
13+
if ( ! src.host || src.host.indexOf( 'opentable' ) === -1 || ! src.search ) {
1414
return;
1515
}
1616

0 commit comments

Comments
 (0)