{"action":"created","issue":{"url":"https://api.github.com/repos/sparklemotion/nokogiri/issues/551","labels_url":"https://api.github.com/repos/sparklemotion/nokogiri/issues/551/labels{/name}","comments_url":"https://api.github.com/repos/sparklemotion/nokogiri/issues/551/comments","events_url":"https://api.github.com/repos/sparklemotion/nokogiri/issues/551/events","html_url":"https://github.com/sparklemotion/nokogiri/issues/551","id":1904604,"number":551,"title":"Parsing without NOENT still substitutes entities","user":{"login":"Phrogz","id":14778,"avatar_url":"https://avatars.githubusercontent.com/u/14778?v=3","gravatar_id":"","url":"https://api.github.com/users/Phrogz","html_url":"https://github.com/Phrogz","followers_url":"https://api.github.com/users/Phrogz/followers","following_url":"https://api.github.com/users/Phrogz/following{/other_user}","gists_url":"https://api.github.com/users/Phrogz/gists{/gist_id}","starred_url":"https://api.github.com/users/Phrogz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Phrogz/subscriptions","organizations_url":"https://api.github.com/users/Phrogz/orgs","repos_url":"https://api.github.com/users/Phrogz/repos","events_url":"https://api.github.com/users/Phrogz/events{/privacy}","received_events_url":"https://api.github.com/users/Phrogz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2011-10-13T20:34:33Z","updated_at":"2015-03-16T16:23:29Z","closed_at":null,"body":"    require 'nokogiri'\r\n    p Nokogiri::VERSION\r\n    #=> \"1.5.0\"\r\n    p [\r\n      Nokogiri::XML::ParseOptions::NOENT,\r\n      Nokogiri::XML::ParseOptions::DEFAULT_HTML\r\n    ].map{ |o| Nokogiri::HTML(\"<p>Foo&reg;</p>\",nil,'utf-8',o).at('//text()') }\r\n    #=> [#<Nokogiri::XML::Text:0x810bb34c \"Foo\\u00AE\">,\r\n    #=>  #<Nokogiri::XML::Text:0x810bafdc \"Foo\\u00AE\">]\r\n\r\nI expected a Nokogiri::XML::EntityReference to be created for those characters that are specified by an entity, e.g.\r\n\r\n    require 'nokogiri'\r\n    doc = Nokogiri::HTML(\"<p>Foo</p>\")\r\n    doc.at('p') << Nokogiri::XML::EntityReference.new( doc, 'reg' )\r\n    p doc.at('p').children\r\n    #=> [#<Nokogiri::XML::Text:0x8092b67c \"Foo\">,\r\n    #=>  #<Nokogiri::XML::EntityReference:0x8092ba3c name=\"reg\">]\r\n\r\nOriginated by trying to answer [this Stack Overflow question](http://stackoverflow.com/questions/7756123/nokogiri-leaving-html-entities-untouched/7759975#7759975)."},"comment":{"url":"https://api.github.com/repos/sparklemotion/nokogiri/issues/comments/81773951","html_url":"https://github.com/sparklemotion/nokogiri/issues/551#issuecomment-81773951","issue_url":"https://api.github.com/repos/sparklemotion/nokogiri/issues/551","id":81773951,"user":{"login":"cheald","id":9830,"avatar_url":"https://avatars.githubusercontent.com/u/9830?v=3","gravatar_id":"","url":"https://api.github.com/users/cheald","html_url":"https://github.com/cheald","followers_url":"https://api.github.com/users/cheald/followers","following_url":"https://api.github.com/users/cheald/following{/other_user}","gists_url":"https://api.github.com/users/cheald/gists{/gist_id}","starred_url":"https://api.github.com/users/cheald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cheald/subscriptions","organizations_url":"https://api.github.com/users/cheald/orgs","repos_url":"https://api.github.com/users/cheald/repos","events_url":"https://api.github.com/users/cheald/events{/privacy}","received_events_url":"https://api.github.com/users/cheald/received_events","type":"User","site_admin":false},"created_at":"2015-03-16T16:23:29Z","updated_at":"2015-03-16T16:23:29Z","body":"@flavorjones That helps a lot! Thank you.\r\n\r\nSpecifically WRT sanitization, it looks like something like this should work:\r\n\r\n    Nokogiri::HTML(\"<div><b>bold</b>&lt;script>alert('Ouch!');&lt;/script></div>\").xpath(\"//text()\").to_html\r\n    # => \"bold&lt;script&gt;alert('Ouch!');&lt;/script&gt;\""}}