{"id":14273712,"date":"2021-04-04T01:22:56","date_gmt":"2021-04-04T01:22:56","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/unescaped-javascript-string\/"},"modified":"2021-04-04T01:22:56","modified_gmt":"2021-04-04T01:22:56","slug":"unescaped-javascript-string","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/unescaped-javascript-string\/","title":{"rendered":"unescaped javascript string"},"content":{"rendered":"<p>While using developer tools on a web page, I noticed the following javascript&#8230;<\/p>\n<p><code>Uncaught SyntaxError: &quot;&quot; string literal contains an unescaped line break<\/code><\/p>\n<p>This error was being caused by the line starting with text: &#8221; in the following script generated by your plugin&#8230;<\/p>\n<pre><code>&lt;script&gt;\n\twindow.addEventListener(&quot;DOMContentLoaded&quot;, function(){\n\t\tif ( navigator.share ) {\n\t\t\t\t\t\t\tlet shareurl = document.location.href;\n\t\t\tlet btns = document.querySelectorAll(&quot;.juiz_sps_link_shareapi button:not([data-bound])&quot;);\n\t\t\tconst canon = document.querySelector(&quot;link[rel=canonical]&quot;);\n\n\t\t\tif (canon !== null) {\n\t\t\t\tshareurl = canon.href;\n\t\t\t}\n\n\t\t\tbtns.forEach(function(el) {\n\t\t\t\t\t\t\t\tel.closest(&quot;.juiz_sps_link_shareapi&quot;).removeAttribute( &quot;style&quot; );\n\t\t\t\tel.setAttribute( &quot;data-bound&quot;, &quot;true&quot; );\n\t\t\t\t\t\t\t\tel.addEventListener(&quot;click&quot;, async () =&gt; {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait navigator.share({\n\t\t\t\t\t\t\t\t\t\t\ttitle: &quot;How To Protect WordPress with CloudFlare Firewall Rules&quot;,\n\t\t\t\t\t\t\t\t\t\t\ttext: &quot;How To Protect WordPress with CloudFlare Firewall Rules - OVERVIEW\nCloudFlare recently added Firewall Rules to all accounts, including&quot;,\n\t\t\t\t\t\t\t\t\t\t\turl: shareurl,\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\tconsole.info(&quot;Successful share&quot;);\n\t\t\t\t\t} catch(err) {\n\t\t\t\t\t\t\t\t\t\tconsole.warn(&quot;Error sharing&quot;, error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\t});\n&lt;\/script&gt;<\/code><\/pre>\n<p>It looks like you could use some esc_js() calls on your javascript string outputs.<\/p>\n<p>Thanks.<\/p>\n","protected":false},"template":"","class_list":["post-14273712","topic","type-topic","status-publish","hentry","topic-tag-javascript"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14273712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14273712\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=14273712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}