{"action":"closed","issue":{"url":"https://api.github.com/repos/lyokato/ruby-atomutil/issues/2","repository_url":"https://api.github.com/repos/lyokato/ruby-atomutil","labels_url":"https://api.github.com/repos/lyokato/ruby-atomutil/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/lyokato/ruby-atomutil/issues/2/comments","events_url":"https://api.github.com/repos/lyokato/ruby-atomutil/issues/2/events","html_url":"https://github.com/lyokato/ruby-atomutil/issues/2","id":356738175,"node_id":"MDU6SXNzdWUzNTY3MzgxNzU=","number":2,"title":"Part of the text set to the content of Atom::Entry is not escaped","user":{"login":"rnanba","id":589746,"node_id":"MDQ6VXNlcjU4OTc0Ng==","avatar_url":"https://avatars0.githubusercontent.com/u/589746?v=4","gravatar_id":"","url":"https://api.github.com/users/rnanba","html_url":"https://github.com/rnanba","followers_url":"https://api.github.com/users/rnanba/followers","following_url":"https://api.github.com/users/rnanba/following{/other_user}","gists_url":"https://api.github.com/users/rnanba/gists{/gist_id}","starred_url":"https://api.github.com/users/rnanba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rnanba/subscriptions","organizations_url":"https://api.github.com/users/rnanba/orgs","repos_url":"https://api.github.com/users/rnanba/repos","events_url":"https://api.github.com/users/rnanba/events{/privacy}","received_events_url":"https://api.github.com/users/rnanba/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-09-04T10:00:33Z","updated_at":"2018-09-04T13:45:07Z","closed_at":"2018-09-04T13:45:06Z","author_association":"NONE","body":"I'm using atomutil 0.1.4 with ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]. The following code outputs `&lt;` and `&gt;` to `content` element content without being escaped.\r\n\r\n```\r\n# coding: utf-8\r\nrequire 'atomutil'\r\nentry = Atom::Entry.new\r\nentry.content = \"&lt;br&gt;\"\r\nputs entry.to_s\r\n```\r\n\r\nresult:\r\n```\r\n<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom'><content type='text'>&lt;br&gt;</content></entry>\r\n```\r\n\r\nexpected:\r\n```\r\n<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom'><content type='text'>&amp;lt;br&amp;gt;</content></entry>\r\n```\r\n\r\nThe example above is assumed to be \"In the blog service accepting posts in text format that can write HTML tags (such as Hatena Blog in Hatena-Notation mode), describe tags with escaped form to explain HTML tags\".\r\n\r\nThe expected result is that the source code of the `br` tag is displayed in the blog entry, but in fact the line feed is displayed (it functions as a real `br` tag).\r\n\r\nThe cause of this issue is that `value.elem.text` in https://github.com/lyokato/ruby-atomutil/blob/954c5d1b387bff63db3462d19d3f7abf196d2b1f/lib/atomutil.rb#L526 returns double unescaped string. This is the bug of `REXML::Text#value` I think, but the maintainer of REXML answered that it can not be fixed because compatibility breaks (see https://bugs.ruby-lang.org/issues/15057).\r\n\r\nInstead, following patch was proposed. Would you please apply it?\r\n\r\n```\r\ndiff --git a/lib/atomutil.rb b/lib/atomutil.rb\r\nindex 9bb9e0c..6d9b985 100644\r\n--- a/lib/atomutil.rb\r\n+++ b/lib/atomutil.rb\r\n@@ -523,7 +523,10 @@ module Atom\r\n             element.add_attribute a\r\n           end\r\n         end\r\n-        element.text = value.elem.text unless value.elem.text.nil?\r\n+        text = value.elem.get_text\r\n+        unless text.nil?\r\n+          element.text = REXML::Text.new(text.to_s, true, nil, true)\r\n+        end\r\n       else\r\n         if value.is_a?(REXML::Element)\r\n           element.add_element value.deep_clone\r\n```\r\n"}}
{"actor":{"display_login":"lyokato"}}