{"action":"created","comment":{"url":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/comments/30298306","id":30298306,"diff_hunk":"@@ -0,0 +1,311 @@\n+/* \n+Copyright (c) 2015, Yahoo Inc. All rights reserved.\n+Copyrights licensed under the New BSD License.\n+See the accompanying LICENSE file for terms.\n+\n+Authors: Nera Liu <neraliu@yahoo-inc.com>\n+         Albert Yu <albertyu@yahoo-inc.com>\n+         Adonis Fung <adon@yahoo-inc.com>\n+*/\n+/*jshint -W030 */\n+/*jshint eqnull:true */\n+(function () {\n+\"use strict\";\n+\n+var fs = require('fs');\n+/* polyfill for codePointAt, fromCodePoint */\n+require('./polyfill.js');\n+\n+/////////////////////////////////////////////////////\n+//\n+// @module HTMLEntities\n+// \n+/////////////////////////////////////////////////////\n+function HTMLEntities(config) {\n+    config || (config = {});\n+    var load = config.load === undefined? true: config.load;\n+\n+    this.namedCharReferenceTrie = [];\n+\n+    if (load) {\n+        var path = __dirname+\"/..\";\n+        var saveFile = path+\"/data/entities.json.save\",\n+            jsonFile = path+\"/data/entities.json\";\n+\n+        if (fs.existsSync(saveFile)) {\n+            this.loadNamedCharReferenceTrie(saveFile);\n+        } else if (fs.existsSync(jsonFile)) {\n+            var d = fs.readFileSync(jsonFile, \"utf8\"),\n+                o = JSON.parse(d);\n+            this.buildNamedCharReferenceTrie(o);\n+        }\n+    }\n+}\n+\n+/////////////////////////////////////////////////////\n+//\n+// PUBLIC API\n+// \n+/////////////////////////////////////////////////////\n+\n+/**\n+* @function HTMLEntities#encode\n+*\n+* @description\n+* HTML encode the character\n+*/\n+HTMLEntities.prototype.encode = function(str) {\n+    var l = str.length,\n+        c, r = '';\n+    for(var i=0;i<l;++i) {\n+        c = str.charCodeAt(i);\n+        // 55296-57343\n+        if (c>=0xD800 && c<=0xDFFF) {\n+            if (i+1<l) {\n+                c = str.codePointAt(i);\n+            }\n+            if (i+1>=l) {\n+                continue; // skip the malformat char\n+            }\n+            i++; // skip the char\n+        }\n+        r += \"&#\"+c+\";\";\n+    }\n+    return r;\n+};\n+\n+/**\n+* @function HTMLEntities#decode\n+*\n+* @description\n+* HTML decode the character\n+*/\n+HTMLEntities.prototype.reCharReferenceDecode = /&(#?)([xX]?)0*([a-zA-Z0-9]+)(;)?/g;\n+HTMLEntities.prototype.fromCodePoint = String.fromCodePoint;\n+HTMLEntities.prototype.decode = function(str) {\n+    /* decode all numeric dec/hex character reference */\n+    var htmlDecoder = this;\n+\n+    str = str.replace(this.reCharReferenceDecode, function(m, isNamed, isHex, p1, p2) {\n+        var s = p2 === undefined? p1 : p1 + p2;\n+\n+        if (isNamed !== '#') {\n+            var obj = htmlDecoder._findString(s);\n+            /* NOTE: != return true for undefined and null */\n+            if (obj != null) {\n+                return obj.characters;\n+            }\n+            return '&'+s;\n+        } else {\n+            var radix = (isHex !== 'x' && isHex !== 'X')? 10:16;\n+            var i = parseInt(p1, radix);\n+            // 0-55295, 57344-65535, 65536-1114111\n+            if ((i>=0 && i<=0xD7FF) || (i>=0xE000 && i<=0xFFFF) || (i>=0x10000 && i<=0x10FFFF)) {\n+                return htmlDecoder.fromCodePoint(i);\n+            } else {\n+               if (isNaN(i)) {\n+                   return '&#'+s; // not html entities","path":"src/html-entities.js","position":106,"original_position":107,"commit_id":"c0b6ab1f367fce7ee23df7a7345d44b5fb146d31","original_commit_id":"f665652d6656ae47889f132fafab9db10861b00d","user":{"login":"adon-at-work","id":8486533,"avatar_url":"https://avatars.githubusercontent.com/u/8486533?v=3","gravatar_id":"","url":"https://api.github.com/users/adon-at-work","html_url":"https://github.com/adon-at-work","followers_url":"https://api.github.com/users/adon-at-work/followers","following_url":"https://api.github.com/users/adon-at-work/following{/other_user}","gists_url":"https://api.github.com/users/adon-at-work/gists{/gist_id}","starred_url":"https://api.github.com/users/adon-at-work/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adon-at-work/subscriptions","organizations_url":"https://api.github.com/users/adon-at-work/orgs","repos_url":"https://api.github.com/users/adon-at-work/repos","events_url":"https://api.github.com/users/adon-at-work/events{/privacy}","received_events_url":"https://api.github.com/users/adon-at-work/received_events","type":"User","site_admin":false},"body":"chrome does that","created_at":"2015-05-14T05:06:32Z","updated_at":"2015-05-14T05:06:32Z","html_url":"https://github.com/yahoo/secure-handlebars/pull/48#discussion_r30298306","pull_request_url":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/48","_links":{"self":{"href":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/comments/30298306"},"html":{"href":"https://github.com/yahoo/secure-handlebars/pull/48#discussion_r30298306"},"pull_request":{"href":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/48"}}},"pull_request":{"url":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/48","id":35310520,"html_url":"https://github.com/yahoo/secure-handlebars/pull/48","diff_url":"https://github.com/yahoo/secure-handlebars/pull/48.diff","patch_url":"https://github.com/yahoo/secure-handlebars/pull/48.patch","issue_url":"https://api.github.com/repos/yahoo/secure-handlebars/issues/48","number":48,"state":"open","locked":false,"title":"html entities encode/decode","user":{"login":"neraliu","id":291417,"avatar_url":"https://avatars.githubusercontent.com/u/291417?v=3","gravatar_id":"","url":"https://api.github.com/users/neraliu","html_url":"https://github.com/neraliu","followers_url":"https://api.github.com/users/neraliu/followers","following_url":"https://api.github.com/users/neraliu/following{/other_user}","gists_url":"https://api.github.com/users/neraliu/gists{/gist_id}","starred_url":"https://api.github.com/users/neraliu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neraliu/subscriptions","organizations_url":"https://api.github.com/users/neraliu/orgs","repos_url":"https://api.github.com/users/neraliu/repos","events_url":"https://api.github.com/users/neraliu/events{/privacy}","received_events_url":"https://api.github.com/users/neraliu/received_events","type":"User","site_admin":false},"body":"this PR includes the following\r\n- build the trie data structure for named char reference look up\r\n- provide the public api of encode/decode for html entities encode/decode\r\n- use the latest html5 named character reference list for html decode.\r\nhttps://html.spec.whatwg.org/multipage/entities.json","created_at":"2015-05-13T09:51:07Z","updated_at":"2015-05-14T05:06:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5f301796861c61f087eced2c0d613c381b0bbf6d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/48/commits","review_comments_url":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/48/comments","review_comment_url":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/comments{/number}","comments_url":"https://api.github.com/repos/yahoo/secure-handlebars/issues/48/comments","statuses_url":"https://api.github.com/repos/yahoo/secure-handlebars/statuses/c0b6ab1f367fce7ee23df7a7345d44b5fb146d31","head":{"label":"neraliu:html-entities-decoding","ref":"html-entities-decoding","sha":"c0b6ab1f367fce7ee23df7a7345d44b5fb146d31","user":{"login":"neraliu","id":291417,"avatar_url":"https://avatars.githubusercontent.com/u/291417?v=3","gravatar_id":"","url":"https://api.github.com/users/neraliu","html_url":"https://github.com/neraliu","followers_url":"https://api.github.com/users/neraliu/followers","following_url":"https://api.github.com/users/neraliu/following{/other_user}","gists_url":"https://api.github.com/users/neraliu/gists{/gist_id}","starred_url":"https://api.github.com/users/neraliu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neraliu/subscriptions","organizations_url":"https://api.github.com/users/neraliu/orgs","repos_url":"https://api.github.com/users/neraliu/repos","events_url":"https://api.github.com/users/neraliu/events{/privacy}","received_events_url":"https://api.github.com/users/neraliu/received_events","type":"User","site_admin":false},"repo":{"id":33704534,"name":"secure-handlebars","full_name":"neraliu/secure-handlebars","owner":{"login":"neraliu","id":291417,"avatar_url":"https://avatars.githubusercontent.com/u/291417?v=3","gravatar_id":"","url":"https://api.github.com/users/neraliu","html_url":"https://github.com/neraliu","followers_url":"https://api.github.com/users/neraliu/followers","following_url":"https://api.github.com/users/neraliu/following{/other_user}","gists_url":"https://api.github.com/users/neraliu/gists{/gist_id}","starred_url":"https://api.github.com/users/neraliu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neraliu/subscriptions","organizations_url":"https://api.github.com/users/neraliu/orgs","repos_url":"https://api.github.com/users/neraliu/repos","events_url":"https://api.github.com/users/neraliu/events{/privacy}","received_events_url":"https://api.github.com/users/neraliu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/neraliu/secure-handlebars","description":"Handlebars Context Pre-compiler","fork":true,"url":"https://api.github.com/repos/neraliu/secure-handlebars","forks_url":"https://api.github.com/repos/neraliu/secure-handlebars/forks","keys_url":"https://api.github.com/repos/neraliu/secure-handlebars/keys{/key_id}","collaborators_url":"https://api.github.com/repos/neraliu/secure-handlebars/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/neraliu/secure-handlebars/teams","hooks_url":"https://api.github.com/repos/neraliu/secure-handlebars/hooks","issue_events_url":"https://api.github.com/repos/neraliu/secure-handlebars/issues/events{/number}","events_url":"https://api.github.com/repos/neraliu/secure-handlebars/events","assignees_url":"https://api.github.com/repos/neraliu/secure-handlebars/assignees{/user}","branches_url":"https://api.github.com/repos/neraliu/secure-handlebars/branches{/branch}","tags_url":"https://api.github.com/repos/neraliu/secure-handlebars/tags","blobs_url":"https://api.github.com/repos/neraliu/secure-handlebars/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/neraliu/secure-handlebars/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/neraliu/secure-handlebars/git/refs{/sha}","trees_url":"https://api.github.com/repos/neraliu/secure-handlebars/git/trees{/sha}","statuses_url":"https://api.github.com/repos/neraliu/secure-handlebars/statuses/{sha}","languages_url":"https://api.github.com/repos/neraliu/secure-handlebars/languages","stargazers_url":"https://api.github.com/repos/neraliu/secure-handlebars/stargazers","contributors_url":"https://api.github.com/repos/neraliu/secure-handlebars/contributors","subscribers_url":"https://api.github.com/repos/neraliu/secure-handlebars/subscribers","subscription_url":"https://api.github.com/repos/neraliu/secure-handlebars/subscription","commits_url":"https://api.github.com/repos/neraliu/secure-handlebars/commits{/sha}","git_commits_url":"https://api.github.com/repos/neraliu/secure-handlebars/git/commits{/sha}","comments_url":"https://api.github.com/repos/neraliu/secure-handlebars/comments{/number}","issue_comment_url":"https://api.github.com/repos/neraliu/secure-handlebars/issues/comments{/number}","contents_url":"https://api.github.com/repos/neraliu/secure-handlebars/contents/{+path}","compare_url":"https://api.github.com/repos/neraliu/secure-handlebars/compare/{base}...{head}","merges_url":"https://api.github.com/repos/neraliu/secure-handlebars/merges","archive_url":"https://api.github.com/repos/neraliu/secure-handlebars/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/neraliu/secure-handlebars/downloads","issues_url":"https://api.github.com/repos/neraliu/secure-handlebars/issues{/number}","pulls_url":"https://api.github.com/repos/neraliu/secure-handlebars/pulls{/number}","milestones_url":"https://api.github.com/repos/neraliu/secure-handlebars/milestones{/number}","notifications_url":"https://api.github.com/repos/neraliu/secure-handlebars/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/neraliu/secure-handlebars/labels{/name}","releases_url":"https://api.github.com/repos/neraliu/secure-handlebars/releases{/id}","created_at":"2015-04-10T02:43:29Z","updated_at":"2015-05-08T07:45:06Z","pushed_at":"2015-05-14T02:36:01Z","git_url":"git://github.com/neraliu/secure-handlebars.git","ssh_url":"git@github.com:neraliu/secure-handlebars.git","clone_url":"https://github.com/neraliu/secure-handlebars.git","svn_url":"https://github.com/neraliu/secure-handlebars","homepage":"","size":2081,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"yahoo:master","ref":"master","sha":"1a111a0764cf1f9cd027b8cdbc52f814bcfb3213","user":{"login":"yahoo","id":16574,"avatar_url":"https://avatars.githubusercontent.com/u/16574?v=3","gravatar_id":"","url":"https://api.github.com/users/yahoo","html_url":"https://github.com/yahoo","followers_url":"https://api.github.com/users/yahoo/followers","following_url":"https://api.github.com/users/yahoo/following{/other_user}","gists_url":"https://api.github.com/users/yahoo/gists{/gist_id}","starred_url":"https://api.github.com/users/yahoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yahoo/subscriptions","organizations_url":"https://api.github.com/users/yahoo/orgs","repos_url":"https://api.github.com/users/yahoo/repos","events_url":"https://api.github.com/users/yahoo/events{/privacy}","received_events_url":"https://api.github.com/users/yahoo/received_events","type":"Organization","site_admin":false},"repo":{"id":30554349,"name":"secure-handlebars","full_name":"yahoo/secure-handlebars","owner":{"login":"yahoo","id":16574,"avatar_url":"https://avatars.githubusercontent.com/u/16574?v=3","gravatar_id":"","url":"https://api.github.com/users/yahoo","html_url":"https://github.com/yahoo","followers_url":"https://api.github.com/users/yahoo/followers","following_url":"https://api.github.com/users/yahoo/following{/other_user}","gists_url":"https://api.github.com/users/yahoo/gists{/gist_id}","starred_url":"https://api.github.com/users/yahoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yahoo/subscriptions","organizations_url":"https://api.github.com/users/yahoo/orgs","repos_url":"https://api.github.com/users/yahoo/repos","events_url":"https://api.github.com/users/yahoo/events{/privacy}","received_events_url":"https://api.github.com/users/yahoo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/yahoo/secure-handlebars","description":"Handlebars Context Pre-compiler","fork":false,"url":"https://api.github.com/repos/yahoo/secure-handlebars","forks_url":"https://api.github.com/repos/yahoo/secure-handlebars/forks","keys_url":"https://api.github.com/repos/yahoo/secure-handlebars/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yahoo/secure-handlebars/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yahoo/secure-handlebars/teams","hooks_url":"https://api.github.com/repos/yahoo/secure-handlebars/hooks","issue_events_url":"https://api.github.com/repos/yahoo/secure-handlebars/issues/events{/number}","events_url":"https://api.github.com/repos/yahoo/secure-handlebars/events","assignees_url":"https://api.github.com/repos/yahoo/secure-handlebars/assignees{/user}","branches_url":"https://api.github.com/repos/yahoo/secure-handlebars/branches{/branch}","tags_url":"https://api.github.com/repos/yahoo/secure-handlebars/tags","blobs_url":"https://api.github.com/repos/yahoo/secure-handlebars/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yahoo/secure-handlebars/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yahoo/secure-handlebars/git/refs{/sha}","trees_url":"https://api.github.com/repos/yahoo/secure-handlebars/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yahoo/secure-handlebars/statuses/{sha}","languages_url":"https://api.github.com/repos/yahoo/secure-handlebars/languages","stargazers_url":"https://api.github.com/repos/yahoo/secure-handlebars/stargazers","contributors_url":"https://api.github.com/repos/yahoo/secure-handlebars/contributors","subscribers_url":"https://api.github.com/repos/yahoo/secure-handlebars/subscribers","subscription_url":"https://api.github.com/repos/yahoo/secure-handlebars/subscription","commits_url":"https://api.github.com/repos/yahoo/secure-handlebars/commits{/sha}","git_commits_url":"https://api.github.com/repos/yahoo/secure-handlebars/git/commits{/sha}","comments_url":"https://api.github.com/repos/yahoo/secure-handlebars/comments{/number}","issue_comment_url":"https://api.github.com/repos/yahoo/secure-handlebars/issues/comments{/number}","contents_url":"https://api.github.com/repos/yahoo/secure-handlebars/contents/{+path}","compare_url":"https://api.github.com/repos/yahoo/secure-handlebars/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yahoo/secure-handlebars/merges","archive_url":"https://api.github.com/repos/yahoo/secure-handlebars/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yahoo/secure-handlebars/downloads","issues_url":"https://api.github.com/repos/yahoo/secure-handlebars/issues{/number}","pulls_url":"https://api.github.com/repos/yahoo/secure-handlebars/pulls{/number}","milestones_url":"https://api.github.com/repos/yahoo/secure-handlebars/milestones{/number}","notifications_url":"https://api.github.com/repos/yahoo/secure-handlebars/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yahoo/secure-handlebars/labels{/name}","releases_url":"https://api.github.com/repos/yahoo/secure-handlebars/releases{/id}","created_at":"2015-02-09T19:35:28Z","updated_at":"2015-05-08T06:07:23Z","pushed_at":"2015-05-14T02:36:01Z","git_url":"git://github.com/yahoo/secure-handlebars.git","ssh_url":"git@github.com:yahoo/secure-handlebars.git","clone_url":"https://github.com/yahoo/secure-handlebars.git","svn_url":"https://github.com/yahoo/secure-handlebars","homepage":"","size":2508,"stargazers_count":7,"watchers_count":7,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/48"},"html":{"href":"https://github.com/yahoo/secure-handlebars/pull/48"},"issue":{"href":"https://api.github.com/repos/yahoo/secure-handlebars/issues/48"},"comments":{"href":"https://api.github.com/repos/yahoo/secure-handlebars/issues/48/comments"},"review_comments":{"href":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/48/comments"},"review_comment":{"href":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/yahoo/secure-handlebars/pulls/48/commits"},"statuses":{"href":"https://api.github.com/repos/yahoo/secure-handlebars/statuses/c0b6ab1f367fce7ee23df7a7345d44b5fb146d31"}}}}