@@ -279,6 +279,75 @@ describe('static check meta tags', function () {
279279 } ) ;
280280 } ) ;
281281
282+ it ( 'jsonLD - invalid JSON string that cannot be parsed does not throw error' , function ( ) {
283+ const metaHTML = `<html><head>
284+ <script type="application/ld+json">
285+ {
286+ "@context": "http://schema.org",
287+ "@type": "Organization",
288+ "name": "Blah ",
289+ "sameAs": [
290+ "https:\\\\/\\\\/twitter.com\\\\/blah?lang=en"
291+ "https:\\\\/\\\\/www.facebook.com\\\\/blah\\\\/"
292+ ""
293+ "https:\\\\/\\\\/www.instagram.com\\\\/blah\\\\/"
294+ ""
295+ ""
296+ "https:\\\\/\\\\/www.youtube.com\\\\/@blah"
297+ ""
298+ ],
299+ "url": "https:\\\\/\\\\/blah.com"
300+ }
301+
302+ </script>
303+ </head></html>` ;
304+
305+ mockAgent . get ( 'http://www.test.com' )
306+ . intercept ( { path : '/' } )
307+ . reply ( 200 , metaHTML ) ;
308+
309+ return ogs ( { url : 'www.test.com' } )
310+ . then ( function ( data ) {
311+ expect ( data . result . success ) . to . be . eql ( true ) ;
312+ expect ( data . result . requestUrl ) . to . be . eql ( 'http://www.test.com' ) ;
313+ expect ( data . result . jsonLD ) . to . be . eql ( [ ] ) ;
314+ expect ( data . html ) . to . be . eql ( metaHTML ) ;
315+ expect ( data . response ) . to . be . a ( 'response' ) ;
316+ } ) ;
317+ } ) ;
318+
319+ it ( 'jsonLD - invalid JSON string that cannot be parsed throws error when options.jsonLDOptions.throwOnJSONParseError = true' , function ( ) {
320+ const metaHTML = `<html><head>
321+ <script type="application/ld+json">
322+ {
323+ "@context": "http://schema.org",
324+ "@type": "Organization",
325+ "name": "Blah ",
326+ "sameAs": [
327+ "https:\\\\/\\\\/twitter.com\\\\/blah?lang=en"
328+ "https:\\\\/\\\\/www.facebook.com\\\\/blah\\\\/"
329+ ""
330+ "https:\\\\/\\\\/www.instagram.com\\\\/blah\\\\/"
331+ ""
332+ ""
333+ "https:\\\\/\\\\/www.youtube.com\\\\/@blah"
334+ ""
335+ ],
336+ "url": "https:\\\\/\\\\/blah.com"
337+ }
338+
339+ </script>
340+ </head></html>` ;
341+
342+ mockAgent . get ( 'http://www.test.com' )
343+ . intercept ( { path : '/' } )
344+ . reply ( 200 , metaHTML ) ;
345+
346+ return ogs ( { url : 'www.test.com' , jsonLDOptions : { throwOnJSONParseError : true } } ) . catch ( ( data ) => {
347+ expect ( data . result . success ) . to . be . eql ( false ) ;
348+ } ) ;
349+ } ) ;
350+
282351 it ( 'encoding - utf-8' , function ( ) {
283352 /* eslint-disable max-len */
284353 const metaHTML = `<html><head>
0 commit comments