{"action":"created","comment":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/comments/174230380","pull_request_review_id":103534106,"id":174230380,"diff_hunk":"@@ -0,0 +1,340 @@\n+// -*- Mode: Go; indent-tabs-mode: t -*-\n+\n+/*\n+ * Copyright (C) 2018 Canonical Ltd\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License version 3 as\n+ * published by the Free Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+ *\n+ */\n+\n+package puritan\n+\n+import (\n+\t\"encoding/json\"\n+\t\"fmt\"\n+\t\"strconv\"\n+\t\"unicode\"\n+\t\"unicode/utf16\"\n+\t\"unicode/utf8\"\n+\t\"unsafe\"\n+\n+\t\"github.com/snapcore/snapd/strutil\"\n+)\n+\n+// SimpleStrings are JSON strings that are representable with no backslashes\n+// (any backslash will be rejected, even if it represents an ASCII character).\n+type SimpleString struct {\n+\ts string\n+}\n+\n+// NewSimpleString returns a new SimpleString whose Clean method returns the given string.\n+//\n+// This is meant for use in testing.\n+func NewSimpleString(s string) SimpleString {\n+\treturn SimpleString{s}\n+}\n+\n+// UnmarshalJSON will return an error if the JSON has anything that is\n+// plain, non-backslashed ASCII.\n+func (un *SimpleString) UnmarshalJSON(in []byte) error {\n+\ts, err := unmarshal(in, uOpt{basic: true})\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tun.s = s\n+\treturn nil\n+}\n+\n+// Clean returns the string.\n+func (un SimpleString) Clean() string {\n+\treturn un.s\n+}\n+\n+// SimpleStringSlice is a slice of SimpleStrings, for convenience\n+type SimpleStringSlice []SimpleString\n+\n+// Clean returns a slice of Clean()ed Strings.\n+func (un SimpleStringSlice) Clean() []string {\n+\tout := make([]string, len(un))\n+\tfor i := range un {\n+\t\tout[i] = un[i].Clean()\n+\t}\n+\n+\treturn out\n+}\n+\n+// String accepts any valid JSON string\n+type String struct {\n+\ts string\n+}\n+\n+// NewString returns a new String whose Clean method returns the given string.\n+//\n+// This is meant for use in testing.\n+func NewString(s string) String {\n+\treturn String{s}\n+}\n+\n+func (un *String) UnmarshalJSON(in []byte) (err error) {\n+\tun.s, err = unmarshal(in, uOpt{})\n+\treturn\n+}\n+\n+// Clean returns the string, with any control characters stripped.\n+func (un String) Clean() string {\n+\treturn un.s\n+}\n+\n+// Paragraph accepts any valid JSON string\n+type Paragraph struct {\n+\ts string\n+}\n+\n+func (un *Paragraph) UnmarshalJSON(in []byte) (err error) {\n+\tun.s, err = unmarshal(in, uOpt{nlok: true})\n+\treturn\n+}\n+\n+// Clean returns the string, with any control characters except \\n stripped.\n+func (un Paragraph) Clean() string {\n+\treturn un.s\n+}\n+\n+// StringSlice is a slice of Strings, for convenience.\n+type StringSlice []String\n+\n+// Clean returns a slice of Clean()ed Strings.\n+func (un StringSlice) Clean() []string {\n+\tout := make([]string, len(un))\n+\tfor i := range un {\n+\t\tout[i] = un[i].Clean()\n+\t}\n+\n+\treturn out\n+}\n+\n+// OldPriceMap is a map for prices in the old API.\n+type OldPriceMap struct {\n+\ts map[string]float64\n+}\n+\n+func (un *OldPriceMap) UnmarshalJSON(in []byte) error {\n+\tvar m map[string]float64\n+\tif err := json.Unmarshal(in, &m); err != nil {\n+\t\treturn err\n+\t}\n+\tfor k := range m {\n+\t\tif !okCurrency(k) {\n+\t\t\treturn fmt.Errorf(\"invalid currency name %q\", k)\n+\t\t}\n+\t}\n+\tun.s = m\n+\n+\treturn nil\n+}\n+\n+// Clean returns a Cleaned map[string]float64.\n+func (un OldPriceMap) Clean() map[string]float64 {\n+\treturn un.s\n+}\n+\n+// PriceMap is a map used for prices.\n+//\n+// the keys are ISO currency codes; the values are strings of floats.\n+type PriceMap struct {\n+\ts map[string]string\n+}\n+\n+func (un *PriceMap) UnmarshalJSON(in []byte) error {\n+\tvar m map[string]string\n+\tif err := json.Unmarshal(in, &m); err != nil {\n+\t\treturn err\n+\t}\n+\tfor k, v := range m {\n+\t\tif !okCurrency(k) {\n+\t\t\treturn fmt.Errorf(\"invalid currency name %q\", k)\n+\t\t}\n+\t\tif !okPrice(v) {\n+\t\t\treturn fmt.Errorf(\"invalid price %q\", v)\n+\t\t}\n+\t}\n+\tun.s = m\n+\n+\treturn nil\n+}\n+\n+// Clean returns a map[string]string of cleaned Strings.\n+func (un PriceMap) Clean() map[string]string {\n+\treturn un.s\n+}\n+\n+func okCurrency(s string) bool {\n+\tif len(s) != 3 {\n+\t\treturn false\n+\t}\n+\tfor _, r := range s {\n+\t\tif r < 'A' || r > 'Z' {\n+\t\t\treturn false\n+\t\t}\n+\t}\n+\treturn true\n+}\n+\n+func okPrice(s string) bool {\n+\t// limits to what strconv.ParseFloat accepts\n+\tfor _, r := range s {\n+\t\tswitch r {\n+\t\tcase '.', '+', '-', 'e', 'E':\n+\t\t\t// ok\n+\t\tdefault:\n+\t\t\tif r < '0' || r > '9' {\n+\t\t\t\treturn false\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn true\n+}\n+\n+func u4(in []byte) rune {\n+\tif len(in) < 6 || in[0] != '\\\\' || in[1] != 'u' {\n+\t\treturn -1","path":"jsonutil/puritan/puritan.go","position":210,"original_position":210,"commit_id":"b6198cea96bb49ffb9491106389c788dac6ff6d8","original_commit_id":"b6198cea96bb49ffb9491106389c788dac6ff6d8","user":{"login":"niemeyer","id":378683,"avatar_url":"https://avatars3.githubusercontent.com/u/378683?v=4","gravatar_id":"","url":"https://api.github.com/users/niemeyer","html_url":"https://github.com/niemeyer","followers_url":"https://api.github.com/users/niemeyer/followers","following_url":"https://api.github.com/users/niemeyer/following{/other_user}","gists_url":"https://api.github.com/users/niemeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/niemeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemeyer/subscriptions","organizations_url":"https://api.github.com/users/niemeyer/orgs","repos_url":"https://api.github.com/users/niemeyer/repos","events_url":"https://api.github.com/users/niemeyer/events{/privacy}","received_events_url":"https://api.github.com/users/niemeyer/received_events","type":"User","site_admin":false},"body":"In the name of all the times our ancestors got this wrong in C :slightly_smiling_face: , can we please make this `return 0, false`?\r\n\r\n","created_at":"2018-03-13T18:02:04Z","updated_at":"2018-03-13T18:58:13Z","html_url":"https://github.com/snapcore/snapd/pull/4790#discussion_r174230380","pull_request_url":"https://api.github.com/repos/snapcore/snapd/pulls/4790","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments/174230380"},"html":{"href":"https://github.com/snapcore/snapd/pull/4790#discussion_r174230380"},"pull_request":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/4790"}}},"pull_request":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/4790","id":173007460,"html_url":"https://github.com/snapcore/snapd/pull/4790","diff_url":"https://github.com/snapcore/snapd/pull/4790.diff","patch_url":"https://github.com/snapcore/snapd/pull/4790.patch","issue_url":"https://api.github.com/repos/snapcore/snapd/issues/4790","number":4790,"state":"open","locked":false,"title":"jsonutil/puritan: introducing puritan.String & etc","user":{"login":"chipaca","id":1543430,"avatar_url":"https://avatars1.githubusercontent.com/u/1543430?v=4","gravatar_id":"","url":"https://api.github.com/users/chipaca","html_url":"https://github.com/chipaca","followers_url":"https://api.github.com/users/chipaca/followers","following_url":"https://api.github.com/users/chipaca/following{/other_user}","gists_url":"https://api.github.com/users/chipaca/gists{/gist_id}","starred_url":"https://api.github.com/users/chipaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipaca/subscriptions","organizations_url":"https://api.github.com/users/chipaca/orgs","repos_url":"https://api.github.com/users/chipaca/repos","events_url":"https://api.github.com/users/chipaca/events{/privacy}","received_events_url":"https://api.github.com/users/chipaca/received_events","type":"User","site_admin":false},"body":"In some cases snapd is given a string it can't be sure is safe to print to\r\nthe user's terminal.\r\n\r\nWith this change, jsonutil will have the tools to deal with that\r\nsafely.  store/details.go and store/details_v2.go use it to decode\r\neverything the store sends.\r\n","created_at":"2018-03-05T22:37:57Z","updated_at":"2018-03-13T18:58:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d9f1a6ae36a05d5d23d5eb881259d58326545791","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/snapcore/snapd/pulls/4790/commits","review_comments_url":"https://api.github.com/repos/snapcore/snapd/pulls/4790/comments","review_comment_url":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/snapcore/snapd/issues/4790/comments","statuses_url":"https://api.github.com/repos/snapcore/snapd/statuses/b6198cea96bb49ffb9491106389c788dac6ff6d8","head":{"label":"chipaca:puritan","ref":"puritan","sha":"b6198cea96bb49ffb9491106389c788dac6ff6d8","user":{"login":"chipaca","id":1543430,"avatar_url":"https://avatars1.githubusercontent.com/u/1543430?v=4","gravatar_id":"","url":"https://api.github.com/users/chipaca","html_url":"https://github.com/chipaca","followers_url":"https://api.github.com/users/chipaca/followers","following_url":"https://api.github.com/users/chipaca/following{/other_user}","gists_url":"https://api.github.com/users/chipaca/gists{/gist_id}","starred_url":"https://api.github.com/users/chipaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipaca/subscriptions","organizations_url":"https://api.github.com/users/chipaca/orgs","repos_url":"https://api.github.com/users/chipaca/repos","events_url":"https://api.github.com/users/chipaca/events{/privacy}","received_events_url":"https://api.github.com/users/chipaca/received_events","type":"User","site_admin":false},"repo":{"id":45061368,"name":"snappy","full_name":"chipaca/snappy","owner":{"login":"chipaca","id":1543430,"avatar_url":"https://avatars1.githubusercontent.com/u/1543430?v=4","gravatar_id":"","url":"https://api.github.com/users/chipaca","html_url":"https://github.com/chipaca","followers_url":"https://api.github.com/users/chipaca/followers","following_url":"https://api.github.com/users/chipaca/following{/other_user}","gists_url":"https://api.github.com/users/chipaca/gists{/gist_id}","starred_url":"https://api.github.com/users/chipaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipaca/subscriptions","organizations_url":"https://api.github.com/users/chipaca/orgs","repos_url":"https://api.github.com/users/chipaca/repos","events_url":"https://api.github.com/users/chipaca/events{/privacy}","received_events_url":"https://api.github.com/users/chipaca/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chipaca/snappy","description":"Snappy is the software at the heart of Ubuntu Core.","fork":true,"url":"https://api.github.com/repos/chipaca/snappy","forks_url":"https://api.github.com/repos/chipaca/snappy/forks","keys_url":"https://api.github.com/repos/chipaca/snappy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chipaca/snappy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chipaca/snappy/teams","hooks_url":"https://api.github.com/repos/chipaca/snappy/hooks","issue_events_url":"https://api.github.com/repos/chipaca/snappy/issues/events{/number}","events_url":"https://api.github.com/repos/chipaca/snappy/events","assignees_url":"https://api.github.com/repos/chipaca/snappy/assignees{/user}","branches_url":"https://api.github.com/repos/chipaca/snappy/branches{/branch}","tags_url":"https://api.github.com/repos/chipaca/snappy/tags","blobs_url":"https://api.github.com/repos/chipaca/snappy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chipaca/snappy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chipaca/snappy/git/refs{/sha}","trees_url":"https://api.github.com/repos/chipaca/snappy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chipaca/snappy/statuses/{sha}","languages_url":"https://api.github.com/repos/chipaca/snappy/languages","stargazers_url":"https://api.github.com/repos/chipaca/snappy/stargazers","contributors_url":"https://api.github.com/repos/chipaca/snappy/contributors","subscribers_url":"https://api.github.com/repos/chipaca/snappy/subscribers","subscription_url":"https://api.github.com/repos/chipaca/snappy/subscription","commits_url":"https://api.github.com/repos/chipaca/snappy/commits{/sha}","git_commits_url":"https://api.github.com/repos/chipaca/snappy/git/commits{/sha}","comments_url":"https://api.github.com/repos/chipaca/snappy/comments{/number}","issue_comment_url":"https://api.github.com/repos/chipaca/snappy/issues/comments{/number}","contents_url":"https://api.github.com/repos/chipaca/snappy/contents/{+path}","compare_url":"https://api.github.com/repos/chipaca/snappy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chipaca/snappy/merges","archive_url":"https://api.github.com/repos/chipaca/snappy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chipaca/snappy/downloads","issues_url":"https://api.github.com/repos/chipaca/snappy/issues{/number}","pulls_url":"https://api.github.com/repos/chipaca/snappy/pulls{/number}","milestones_url":"https://api.github.com/repos/chipaca/snappy/milestones{/number}","notifications_url":"https://api.github.com/repos/chipaca/snappy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chipaca/snappy/labels{/name}","releases_url":"https://api.github.com/repos/chipaca/snappy/releases{/id}","deployments_url":"https://api.github.com/repos/chipaca/snappy/deployments","created_at":"2015-10-27T18:26:51Z","updated_at":"2016-05-24T12:18:49Z","pushed_at":"2018-03-13T15:31:38Z","git_url":"git://github.com/chipaca/snappy.git","ssh_url":"git@github.com:chipaca/snappy.git","clone_url":"https://github.com/chipaca/snappy.git","svn_url":"https://github.com/chipaca/snappy","homepage":null,"size":60331,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"snapcore:master","ref":"master","sha":"e80475a6a467ecf997847a659b76c522b011006f","user":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars1.githubusercontent.com/u/19532717?v=4","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"repo":{"id":44672744,"name":"snapd","full_name":"snapcore/snapd","owner":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars1.githubusercontent.com/u/19532717?v=4","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/snapcore/snapd","description":"The snapd and snap tools enable systems to work with .snap files.","fork":false,"url":"https://api.github.com/repos/snapcore/snapd","forks_url":"https://api.github.com/repos/snapcore/snapd/forks","keys_url":"https://api.github.com/repos/snapcore/snapd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/snapcore/snapd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/snapcore/snapd/teams","hooks_url":"https://api.github.com/repos/snapcore/snapd/hooks","issue_events_url":"https://api.github.com/repos/snapcore/snapd/issues/events{/number}","events_url":"https://api.github.com/repos/snapcore/snapd/events","assignees_url":"https://api.github.com/repos/snapcore/snapd/assignees{/user}","branches_url":"https://api.github.com/repos/snapcore/snapd/branches{/branch}","tags_url":"https://api.github.com/repos/snapcore/snapd/tags","blobs_url":"https://api.github.com/repos/snapcore/snapd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/snapcore/snapd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/snapcore/snapd/git/refs{/sha}","trees_url":"https://api.github.com/repos/snapcore/snapd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/snapcore/snapd/statuses/{sha}","languages_url":"https://api.github.com/repos/snapcore/snapd/languages","stargazers_url":"https://api.github.com/repos/snapcore/snapd/stargazers","contributors_url":"https://api.github.com/repos/snapcore/snapd/contributors","subscribers_url":"https://api.github.com/repos/snapcore/snapd/subscribers","subscription_url":"https://api.github.com/repos/snapcore/snapd/subscription","commits_url":"https://api.github.com/repos/snapcore/snapd/commits{/sha}","git_commits_url":"https://api.github.com/repos/snapcore/snapd/git/commits{/sha}","comments_url":"https://api.github.com/repos/snapcore/snapd/comments{/number}","issue_comment_url":"https://api.github.com/repos/snapcore/snapd/issues/comments{/number}","contents_url":"https://api.github.com/repos/snapcore/snapd/contents/{+path}","compare_url":"https://api.github.com/repos/snapcore/snapd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/snapcore/snapd/merges","archive_url":"https://api.github.com/repos/snapcore/snapd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/snapcore/snapd/downloads","issues_url":"https://api.github.com/repos/snapcore/snapd/issues{/number}","pulls_url":"https://api.github.com/repos/snapcore/snapd/pulls{/number}","milestones_url":"https://api.github.com/repos/snapcore/snapd/milestones{/number}","notifications_url":"https://api.github.com/repos/snapcore/snapd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/snapcore/snapd/labels{/name}","releases_url":"https://api.github.com/repos/snapcore/snapd/releases{/id}","deployments_url":"https://api.github.com/repos/snapcore/snapd/deployments","created_at":"2015-10-21T11:51:46Z","updated_at":"2018-03-13T01:26:06Z","pushed_at":"2018-03-13T17:25:51Z","git_url":"git://github.com/snapcore/snapd.git","ssh_url":"git@github.com:snapcore/snapd.git","clone_url":"https://github.com/snapcore/snapd.git","svn_url":"https://github.com/snapcore/snapd","homepage":"","size":60418,"stargazers_count":893,"watchers_count":893,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":223,"mirror_url":null,"archived":false,"open_issues_count":53,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0"},"forks":223,"open_issues":53,"watchers":893,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/4790"},"html":{"href":"https://github.com/snapcore/snapd/pull/4790"},"issue":{"href":"https://api.github.com/repos/snapcore/snapd/issues/4790"},"comments":{"href":"https://api.github.com/repos/snapcore/snapd/issues/4790/comments"},"review_comments":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/4790/comments"},"review_comment":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/4790/commits"},"statuses":{"href":"https://api.github.com/repos/snapcore/snapd/statuses/b6198cea96bb49ffb9491106389c788dac6ff6d8"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"niemeyer"}}