{"id":8597093,"date":"2016-12-28T15:45:11","date_gmt":"2016-12-28T15:45:11","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/directory_separator-issue\/"},"modified":"2016-12-28T15:45:11","modified_gmt":"2016-12-28T15:45:11","slug":"directory_separator-issue","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/directory_separator-issue\/","title":{"rendered":"DIRECTORY_SEPARATOR Issue"},"content":{"rendered":"<p>Firstly, let me say I&#8217;m aware that this has been <a href=\"\/\/wordpress.org\/support\/topic\/plugin-breaks-on-windows-due-to-phps-directory_separator-constant\/\" target=\"_blank\">reported before<\/a> and that there&#8217;s a work-around. However, if the plug-in is upgraded or re-installed, then the work-around gets undone. Although not a show-stopper, it&#8217;s an annoyance.<\/p>\n<p>There are problems when the directory separator is <code>\\<\/code> rather than <code>\/<\/code>. To my knowledge, this is only Windows platforms, but as that&#8217;s a popular platform, I think this is important.<\/p>\n<p>#### Steps to reproduce:<\/p>\n<ol>\n<li>Use a WordPress site running on a Windows host.<\/li>\n<li>Install and activate &#8220;Snow Storm&#8221;.<\/li>\n<li>Load a page.<\/li>\n<li>Examine the source code.<\/li>\n<\/ol>\n<p>#### Expected behaviour:<\/p>\n<ul>\n<li>The JavaScript file <code>snow-storm.js<\/code> to be loaded, e.g.<br \/>\n\t<code>&lt;script type=&#039;text\/javascript&#039; src=&#039;\/wp-content\/plugins\/snow-storm\/snow-storm.js?ver=1.41&#039;&gt;&lt;\/script&gt;<\/code><\/li>\n<li>The snow effect to be rendered.<\/li>\n<\/ul>\n<p>#### Actual behaviour:<\/p>\n<ul>\n<li>Incorrect script path specified, e.g.<br \/>\n\t<code>&lt;script type=&#039;text\/javascript&#039; src=&#039;\/wp-content\/pluginssnow-stormsnow-storm.js?ver=1.41&#039;&gt;&lt;\/script&gt;<\/code><\/li>\n<li>No snow effect.<\/li>\n<\/ul>\n<p>#### Analysis:<\/p>\n<p>File: snow-storm.php<br \/>\nFunc: snow_storm_enqueue_scripts()<br \/>\nLine: 116<\/p>\n<p>\t<code>wp_enqueue_script(&#039;snow-storm&#039;, plugins_url() . DS . &#039;snow-storm&#039; . DS . &#039;snow-storm.js&#039;, false, &#039;1.41&#039;);<\/code><\/p>\n<p>Due to the use of <code>DS<\/code> i.e. <code>DIRECTORY_SEPARATOR<\/code>, the resulting URL is:<\/p>\n<p>\t<code>\/wp-content\/plugins\\snow-storm\\snow-storm.js<\/code><\/p>\n<p>This is causing problems later on in the processing, since the backslashes are not escaped, e.g.<code>\\\\<\/code>. The result is that things like <code>\\s<\/code> just end up as <code>s<\/code>.<\/p>\n<p>#### Recommendation:<\/p>\n<p>As Windows supports the use of <code>\/<\/code> as a path separator, at least those versions since <code>command.com<\/code> was in use, then there&#8217;s no real need to use the <code>DS<\/code> constant. It could be removed from the plug-in&#8217;s code, or at least permanently set to <code>\/<\/code> rather than <code>DIRECTORY_SEPARATOR<\/code>.<\/p>\n<p>In any case, scripts should be specified as URLs when using <code>&lt;script src=&quot;...&quot;&gt;<\/code>, not file system paths, so <code>DS<\/code> should never have been used in this particular case.<\/p>\n<p>I hope this is helpful.<\/p>\n","protected":false},"template":"","class_list":["post-8597093","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8597093","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\/8597093\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=8597093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}