{"action":"created","issue":{"url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/647","labels_url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/647/labels{/name}","comments_url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/647/comments","events_url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/647/events","html_url":"https://github.com/BrowserSync/browser-sync/issues/647","id":81839695,"number":647,"title":"The hostname is replaced globally in the HTML, even inappropiately","user":{"login":"Flimm","id":355454,"avatar_url":"https://avatars.githubusercontent.com/u/355454?v=3","gravatar_id":"","url":"https://api.github.com/users/Flimm","html_url":"https://github.com/Flimm","followers_url":"https://api.github.com/users/Flimm/followers","following_url":"https://api.github.com/users/Flimm/following{/other_user}","gists_url":"https://api.github.com/users/Flimm/gists{/gist_id}","starred_url":"https://api.github.com/users/Flimm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Flimm/subscriptions","organizations_url":"https://api.github.com/users/Flimm/orgs","repos_url":"https://api.github.com/users/Flimm/repos","events_url":"https://api.github.com/users/Flimm/events{/privacy}","received_events_url":"https://api.github.com/users/Flimm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-28T09:09:36Z","updated_at":"2015-05-28T10:41:29Z","closed_at":null,"body":"Take this command:\r\n\r\n     browser-sync start --proxy experiment\r\n\r\n(I have set up `/etc/hosts` to make http://experiment work.)\r\n\r\nThe `index.html` file being served contains this content:\r\n```html\r\n    <!doctype html>\r\n    <html><body>\r\n    <p>This is an experiment</p>\r\n    <p><img src=\"/images/experiment/example.jpg\"></p>\r\n    <!-- This experiment should prove interesting -->\r\n    <p><a href=\"http://experiment/example.html\">Link</a></p>\r\n    </body></html>\r\n```\r\nHowever, the content that ends up being served on http://localhost:3002 looks like this:\r\n```html\r\n    <!doctype html>\r\n    <html><body><script type='text/javascript' id=\"__bs_script__\">//<![CDATA[\r\n        document.write(\"<script async src='/browser-sync/browser-sync-client.2.7.5.js'><\\/script>\".replace(\"HOST\", location.hostname));\r\n    //]]></script>\r\n    <p>This is an localhost:3002</p>\r\n    <p><img src=\"/images/localhost:3002/example.jpg\"></p>\r\n    <!-- This localhost:3002 should prove interesting -->\r\n    <p><a href=\"//localhost:3002/example.html\">Link</a></p>\r\n    </body></html>\r\n```\r\n\r\nIt seems like Browsersync is simply replacing all instances of `experiment` it finds with `localhost:3002`. This is noticeable straight away, as the image fails to load.\r\n\r\nThere are several errors:\r\n\r\n- Text nodes should be left as is (eg: `<p>This is an experiment</p>` should remain as is).\r\n- Attributes that refer to URLs should treat URLs intelligently, transforming `/images/experiment/example.jpg` to `/images/localhost:3002/example.jpg` is incorrect, but transforming `http://experiment/example.html` to `//localhost:3002/example.html` is correct.\r\n- Replacing text inside comments should not happen."},"comment":{"url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/comments/106268636","html_url":"https://github.com/BrowserSync/browser-sync/issues/647#issuecomment-106268636","issue_url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/647","id":106268636,"user":{"login":"shakyShane","id":1643522,"avatar_url":"https://avatars.githubusercontent.com/u/1643522?v=3","gravatar_id":"","url":"https://api.github.com/users/shakyShane","html_url":"https://github.com/shakyShane","followers_url":"https://api.github.com/users/shakyShane/followers","following_url":"https://api.github.com/users/shakyShane/following{/other_user}","gists_url":"https://api.github.com/users/shakyShane/gists{/gist_id}","starred_url":"https://api.github.com/users/shakyShane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shakyShane/subscriptions","organizations_url":"https://api.github.com/users/shakyShane/orgs","repos_url":"https://api.github.com/users/shakyShane/repos","events_url":"https://api.github.com/users/shakyShane/events{/privacy}","received_events_url":"https://api.github.com/users/shakyShane/received_events","type":"User","site_admin":false},"created_at":"2015-05-28T10:41:29Z","updated_at":"2015-05-28T10:41:29Z","body":"basically, we don't want to get into the game of trying parse html on every request, so we try our best to make it work with string replacements only"}}