{"action":"created","issue":{"url":"https://api.github.com/repos/wp-media/wp-rocket/issues/787","repository_url":"https://api.github.com/repos/wp-media/wp-rocket","labels_url":"https://api.github.com/repos/wp-media/wp-rocket/issues/787/labels{/name}","comments_url":"https://api.github.com/repos/wp-media/wp-rocket/issues/787/comments","events_url":"https://api.github.com/repos/wp-media/wp-rocket/issues/787/events","html_url":"https://github.com/wp-media/wp-rocket/issues/787","id":301480474,"number":787,"title":"“Cut off” asset URLs in generated files (minify, busting) on virtual host","user":{"login":"glueckpress","id":308422,"avatar_url":"https://avatars1.githubusercontent.com/u/308422?v=4","gravatar_id":"","url":"https://api.github.com/users/glueckpress","html_url":"https://github.com/glueckpress","followers_url":"https://api.github.com/users/glueckpress/followers","following_url":"https://api.github.com/users/glueckpress/following{/other_user}","gists_url":"https://api.github.com/users/glueckpress/gists{/gist_id}","starred_url":"https://api.github.com/users/glueckpress/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glueckpress/subscriptions","organizations_url":"https://api.github.com/users/glueckpress/orgs","repos_url":"https://api.github.com/users/glueckpress/repos","events_url":"https://api.github.com/users/glueckpress/events{/privacy}","received_events_url":"https://api.github.com/users/glueckpress/received_events","type":"User","site_admin":false},"labels":[{"id":403829427,"url":"https://api.github.com/repos/wp-media/wp-rocket/labels/bug","name":"bug","color":"ee0701","default":true},{"id":403842882,"url":"https://api.github.com/repos/wp-media/wp-rocket/labels/minor","name":"minor","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":{"login":"Tabrisrp","id":3465180,"avatar_url":"https://avatars3.githubusercontent.com/u/3465180?v=4","gravatar_id":"","url":"https://api.github.com/users/Tabrisrp","html_url":"https://github.com/Tabrisrp","followers_url":"https://api.github.com/users/Tabrisrp/followers","following_url":"https://api.github.com/users/Tabrisrp/following{/other_user}","gists_url":"https://api.github.com/users/Tabrisrp/gists{/gist_id}","starred_url":"https://api.github.com/users/Tabrisrp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tabrisrp/subscriptions","organizations_url":"https://api.github.com/users/Tabrisrp/orgs","repos_url":"https://api.github.com/users/Tabrisrp/repos","events_url":"https://api.github.com/users/Tabrisrp/events{/privacy}","received_events_url":"https://api.github.com/users/Tabrisrp/received_events","type":"User","site_admin":false},"assignees":[{"login":"Tabrisrp","id":3465180,"avatar_url":"https://avatars3.githubusercontent.com/u/3465180?v=4","gravatar_id":"","url":"https://api.github.com/users/Tabrisrp","html_url":"https://github.com/Tabrisrp","followers_url":"https://api.github.com/users/Tabrisrp/followers","following_url":"https://api.github.com/users/Tabrisrp/following{/other_user}","gists_url":"https://api.github.com/users/Tabrisrp/gists{/gist_id}","starred_url":"https://api.github.com/users/Tabrisrp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tabrisrp/subscriptions","organizations_url":"https://api.github.com/users/Tabrisrp/orgs","repos_url":"https://api.github.com/users/Tabrisrp/repos","events_url":"https://api.github.com/users/Tabrisrp/events{/privacy}","received_events_url":"https://api.github.com/users/Tabrisrp/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2018-03-01T16:54:15Z","updated_at":"2018-03-23T14:02:37Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"On a virtual host environment, I got a lot of these “cut off” URLs in CSS files generated by WP Rocket (simplified for brevity):\n\n```css\n@font-face {\nfont-family: 'Some-Font';\nsrc: url('te.example.com/wp-content/path/to/font.woff2');\n}\n```\n\nInstead, it should have been this:\n\n```css\n@font-face {\nfont-family: 'Some-Font';\nsrc: url( 'https://wesite.example.com/wp-content/path/to/font.woff2' );\n}\n```\n\nTurns out, this is the problem:\n\nhttps://github.com/wp-media/wp-rocket/blob/2bc483d9a088adddcf5b9a2983bf2c476a8283a4/inc/vendors/classes/class-minify-css-urirewriter.php#L48\n\n`$_SERVER['DOCUMENT_ROOT']` is unreliable here, since it is not always identical with WordPress’ `ABSPATH`. \n\nThis can result in wrong substrings when absolute URLs get re-assembled from path fragments:\n\nhttps://github.com/wp-media/wp-rocket/blob/2bc483d9a088adddcf5b9a2983bf2c476a8283a4/inc/vendors/classes/class-minify-css-urirewriter.php#L174\n\n## Example:\n\n\n* `$_SERVER['DOCUMENT_ROOT']` returns `/var/www/virtual/example/html`\n* `ABSPATH` returns `'/var/www/virtual/example/website.example.com`\n\nWhat we need to end up with is a path fragment starting with `/wp-content/`, which then can be used to re-assemble the URL. \n\nSo trimming `$_SERVER['DOCUMENT_ROOT']` from the beginning of a path won’t when it isn’t identical with `ABSPATH`.\n\n## Solution\nReplacing the server variable with WordPress’ constant in [/inc/vendors/classes/class-minify-css-urirewriter.php#L48](https://github.com/wp-media/wp-rocket/blob/2bc483d9a088adddcf5b9a2983bf2c476a8283a4/inc/vendors/classes/class-minify-css-urirewriter.php#L48) did the trick:\n\n```php\n$docRoot ? $docRoot : ABSPATH\n```\n\n"},"comment":{"url":"https://api.github.com/repos/wp-media/wp-rocket/issues/comments/375674694","html_url":"https://github.com/wp-media/wp-rocket/issues/787#issuecomment-375674694","issue_url":"https://api.github.com/repos/wp-media/wp-rocket/issues/787","id":375674694,"user":{"login":"glueckpress","id":308422,"avatar_url":"https://avatars1.githubusercontent.com/u/308422?v=4","gravatar_id":"","url":"https://api.github.com/users/glueckpress","html_url":"https://github.com/glueckpress","followers_url":"https://api.github.com/users/glueckpress/followers","following_url":"https://api.github.com/users/glueckpress/following{/other_user}","gists_url":"https://api.github.com/users/glueckpress/gists{/gist_id}","starred_url":"https://api.github.com/users/glueckpress/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glueckpress/subscriptions","organizations_url":"https://api.github.com/users/glueckpress/orgs","repos_url":"https://api.github.com/users/glueckpress/repos","events_url":"https://api.github.com/users/glueckpress/events{/privacy}","received_events_url":"https://api.github.com/users/glueckpress/received_events","type":"User","site_admin":false},"created_at":"2018-03-23T14:02:37Z","updated_at":"2018-03-23T14:02:37Z","author_association":"CONTRIBUTOR","body":"@Tabrisrp Ignore me if this is stupid, but `$_SERVER['SCRIPT_FILENAME']`? Are there scenarios where it returns something else than the path to root level index.php (even when moved one level up)?"}}
{"actor":{"display_login":"glueckpress"}}