diff --git a/NOTICE.txt b/NOTICE.txt index 835d6c3d4e5..9ef031599e2 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -413,8 +413,8 @@ Elasticsearch, B.V. (https://www.elastic.co/). -------------------------------------------------------------------- Dependency: github.com/elastic/go-structform -Version: v0.0.3 -Revision: 0a66add879601f69f55663f4c913c72988218982 +Version: v0.0.4 +Revision: 0ea09ff9b43c387dd183a4088f6d573bf823e4ed License type (autodetected): Apache-2.0 ./vendor/github.com/elastic/go-structform/LICENSE: -------------------------------------------------------------------- diff --git a/vendor/github.com/elastic/go-structform/CHANGELOG.md b/vendor/github.com/elastic/go-structform/CHANGELOG.md index 75c47ed9554..74d0ef234a2 100644 --- a/vendor/github.com/elastic/go-structform/CHANGELOG.md +++ b/vendor/github.com/elastic/go-structform/CHANGELOG.md @@ -14,6 +14,11 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +## [0.0.4] + +### Added +- Add SetEscapeHTML to json visitor. (PR #4) + ## [0.0.3] ### Added diff --git a/vendor/github.com/elastic/go-structform/json/visitor.go b/vendor/github.com/elastic/go-structform/json/visitor.go index 756fde75298..75d62009af6 100644 --- a/vendor/github.com/elastic/go-structform/json/visitor.go +++ b/vendor/github.com/elastic/go-structform/json/visitor.go @@ -19,6 +19,8 @@ type Visitor struct { first boolStack inArray boolStack + + escapeSet []bool } type boolStack struct { @@ -29,20 +31,50 @@ type boolStack struct { var _ structform.Visitor = &Visitor{} +var htmlEscapeSet = [utf8.RuneSelf]bool{} +var jsonEscapeSet = [utf8.RuneSelf]bool{} + type writer struct { out io.Writer } +func init() { + // control characters must be escaped + for i := 0; i < 32; i++ { + htmlEscapeSet[i] = true + jsonEscapeSet[i] = true + } + + // json string required escaping + for _, c := range "\"\\" { + htmlEscapeSet[c] = true + jsonEscapeSet[c] = true + } + + // html escaping + for _, c := range "&<>" { + htmlEscapeSet[c] = true + } +} + func (w writer) write(b []byte) error { _, err := w.out.Write(b) return err } func NewVisitor(out io.Writer) *Visitor { - v := &Visitor{w: writer{out}} + v := &Visitor{w: writer{out}, escapeSet: htmlEscapeSet[:]} return v } +func (v *Visitor) SetEscapeHTML(b bool) { + if b { + v.escapeSet = htmlEscapeSet[:] + } else { + v.escapeSet = jsonEscapeSet[:] + } +} + func (vs *Visitor) writeByte(b byte) error { vs.scratch[0] = b return vs.w.write(vs.scratch[:1]) @@ -139,14 +171,17 @@ func (vs *Visitor) OnString(s string) error { return err } + escapeSet := vs.escapeSet + vs.writeByte('"') start := 0 for i := 0; i < len(s); { if b := s[i]; b < utf8.RuneSelf { - if 0x20 <= b && b != '\\' && b != '"' && b != '<' && b != '>' && b != '&' { + if !escapeSet[b] { i++ continue } + if start < i { vs.writeString(s[start:i]) } diff --git a/vendor/vendor.json b/vendor/vendor.json index 7d571db4e1a..1e92662ee7a 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -482,44 +482,56 @@ "revisionTime": "2018-05-17T07:14:48Z" }, { - "checksumSHA1": "AaEPt+KMknLXze11YOnBGKzP3aA=", + "checksumSHA1": "BY+a5iQICad7U2AZqwej2SIW9J8=", "path": "github.com/elastic/go-structform", - "revision": "0a66add879601f69f55663f4c913c72988218982", - "revisionTime": "2018-03-09T00:36:09Z", - "version": "v0.0.3", - "versionExact": "v0.0.3" + "revision": "0ea09ff9b43c387dd183a4088f6d573bf823e4ed", + "revisionTime": "2018-06-27T12:43:37Z", + "version": "v0.0.4", + "versionExact": "v0.0.4" }, { "checksumSHA1": "SXsT/tWnjLqR8dBiJGZqxCyuNaY=", "path": "github.com/elastic/go-structform/cborl", - "revision": "0a66add879601f69f55663f4c913c72988218982", - "revisionTime": "2018-03-09T00:36:09Z", - "version": "v0.0.3", - "versionExact": "v0.0.3" + "revision": "0ea09ff9b43c387dd183a4088f6d573bf823e4ed", + "revisionTime": "2018-06-27T12:43:37Z", + "version": "v0.0.4", + "versionExact": "v0.0.4" }, { "checksumSHA1": "LUbWdzbpzhBh+5TizsScD8gTm4M=", "path": "github.com/elastic/go-structform/gotype", - "revision": "0a66add879601f69f55663f4c913c72988218982", - "revisionTime": "2018-03-09T00:36:09Z", - "version": "v0.0.3", - "versionExact": "v0.0.3" + "revision": "0ea09ff9b43c387dd183a4088f6d573bf823e4ed", + "revisionTime": "2018-06-27T12:43:37Z", + "version": "v0.0.4", + "versionExact": "v0.0.4" + }, + { + "path": "github.com/elastic/go-structform/internal/ubjson", + "revision": "v0.0.4", + "version": "v0.0.4", + "versionExact": "v0.0.4" }, { "checksumSHA1": "s7k0vEuuqkoPXU0FtrD6Y0jxd7U=", "path": "github.com/elastic/go-structform/internal/unsafe", - "revision": "0a66add879601f69f55663f4c913c72988218982", - "revisionTime": "2018-03-09T00:36:09Z", - "version": "v0.0.3", - "versionExact": "v0.0.3" + "revision": "0ea09ff9b43c387dd183a4088f6d573bf823e4ed", + "revisionTime": "2018-06-27T12:43:37Z", + "version": "v0.0.4", + "versionExact": "v0.0.4" + }, + { + "path": "github.com/elastic/go-structform/internal/visitors", + "revision": "", + "version": "v0.0.4", + "versionExact": "v0.0.4" }, { - "checksumSHA1": "s5nSu8O8TOv4DZhdbU7OC5x0C50=", + "checksumSHA1": "KTDpLMZRFtSVeUuXdaz5o5ehzfI=", "path": "github.com/elastic/go-structform/json", - "revision": "0a66add879601f69f55663f4c913c72988218982", - "revisionTime": "2018-03-09T00:36:09Z", - "version": "v0.0.3", - "versionExact": "v0.0.3" + "revision": "0ea09ff9b43c387dd183a4088f6d573bf823e4ed", + "revisionTime": "2018-06-27T12:43:37Z", + "version": "v0.0.4", + "versionExact": "v0.0.4" }, { "checksumSHA1": "PDqC4Sh2H2EIxVhWZHdsusBMPB8=",