diff -Nru golang-github-pelletier-go-toml-1.9.0/cmd/tomll/main.go golang-github-pelletier-go-toml-1.9.4/cmd/tomll/main.go --- golang-github-pelletier-go-toml-1.9.0/cmd/tomll/main.go 2021-03-26 00:57:38.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/cmd/tomll/main.go 2021-09-06 01:38:35.000000000 +0000 @@ -6,6 +6,7 @@ package main import ( + "bytes" "flag" "fmt" "io" @@ -16,6 +17,7 @@ ) func main() { + multiLineArray := flag.Bool("multiLineArray", false, "sets up the linter to encode arrays with more than one element on multiple lines instead of one.") flag.Usage = func() { fmt.Fprintln(os.Stderr, "tomll can be used in two ways:") fmt.Fprintln(os.Stderr, "Writing to STDIN and reading from STDOUT:") @@ -25,11 +27,16 @@ fmt.Fprintln(os.Stderr, " tomll a.toml b.toml c.toml") fmt.Fprintln(os.Stderr, "") fmt.Fprintln(os.Stderr, "When given a list of files, tomll will modify all files in place without asking.") + fmt.Fprintln(os.Stderr, "When given a list of files, tomll will modify all files in place without asking.") + fmt.Fprintln(os.Stderr, "") + fmt.Fprintln(os.Stderr, "Flags:") + fmt.Fprintln(os.Stderr, "-multiLineArray sets up the linter to encode arrays with more than one element on multiple lines instead of one.") } flag.Parse() + // read from stdin and print to stdout if flag.NArg() == 0 { - s, err := lintReader(os.Stdin) + s, err := lintReader(os.Stdin, *multiLineArray) if err != nil { io.WriteString(os.Stderr, err.Error()) os.Exit(-1) @@ -38,7 +45,7 @@ } else { // otherwise modify a list of files for _, filename := range flag.Args() { - s, err := lintFile(filename) + s, err := lintFile(filename, *multiLineArray) if err != nil { io.WriteString(os.Stderr, err.Error()) os.Exit(-1) @@ -48,18 +55,29 @@ } } -func lintFile(filename string) (string, error) { +func lintFile(filename string, multiLineArray bool) (string, error) { tree, err := toml.LoadFile(filename) if err != nil { return "", err } - return tree.String(), nil + + buf := new(bytes.Buffer) + if err := toml.NewEncoder(buf).ArraysWithOneElementPerLine(multiLineArray).Encode(tree); err != nil { + panic(err) + } + + return buf.String(), nil } -func lintReader(r io.Reader) (string, error) { +func lintReader(r io.Reader, multiLineArray bool) (string, error) { tree, err := toml.LoadReader(r) if err != nil { return "", err } - return tree.String(), nil + + buf := new(bytes.Buffer) + if err := toml.NewEncoder(buf).ArraysWithOneElementPerLine(multiLineArray).Encode(tree); err != nil { + panic(err) + } + return buf.String(), nil } diff -Nru golang-github-pelletier-go-toml-1.9.0/debian/changelog golang-github-pelletier-go-toml-1.9.4/debian/changelog --- golang-github-pelletier-go-toml-1.9.0/debian/changelog 2021-09-04 11:22:40.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/debian/changelog 2021-10-20 09:23:42.000000000 +0000 @@ -1,3 +1,13 @@ +golang-github-pelletier-go-toml (1.9.4-1) unstable; urgency=medium + + * New upstream version 1.9.4 + * Update debian/watch to fix filenamemangle and to track v1. + v2 is now in beta and will be packaged separately. + * debian/copyright: Clarify that localtime.go and localtime_test.go + are Copyright 2016 Google LLC and are licensed under Apache-2.0 + + -- Anthony Fok Wed, 20 Oct 2021 03:23:42 -0600 + golang-github-pelletier-go-toml (1.9.0-1) unstable; urgency=medium * New upstream version 1.9.0 diff -Nru golang-github-pelletier-go-toml-1.9.0/debian/copyright golang-github-pelletier-go-toml-1.9.4/debian/copyright --- golang-github-pelletier-go-toml-1.9.0/debian/copyright 2019-07-12 00:31:48.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/debian/copyright 2021-10-20 09:20:07.000000000 +0000 @@ -3,14 +3,46 @@ Source: https://github.com/pelletier/go-toml Files: * -Copyright: © 2013-2019 Thomas Pelletier, Eric Anderton +Copyright: © 2013-2021 Thomas Pelletier, Eric Anderton License: Expat +Files: localtime.go + localtime_test.go +Copyright: © 2016 Google LLC +License: Apache-2.0 +Comment: + Copied over from Google's civil to avoid pulling all the Google dependencies. + Originals: + https://raw.githubusercontent.com/googleapis/google-cloud-go/ed46f5086358513cf8c25f8e3f022cb838a49d66/civil/civil.go + https://raw.githubusercontent.com/googleapis/google-cloud-go/ed46f5086358513cf8c25f8e3f022cb838a49d66/civil/civil_test.go + Changes: + * Renamed files from civil* to localtime*. + * Package changed from civil to toml. + * 'Local' prefix added to all structs. + License: + https://raw.githubusercontent.com/googleapis/google-cloud-go/ed46f5086358513cf8c25f8e3f022cb838a49d66/LICENSE + Files: debian/* Copyright: © 2016-2019 Dr. Tobias Quathamer License: Expat Comment: Debian packaging is licensed under the same terms as upstream +License: Apache-2.0 + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + . + http://www.apache.org/licenses/LICENSE-2.0 + . + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +Comment: + On Debian systems, the complete text of the Apache version 2.0 license + can be found in "/usr/share/common-licenses/Apache-2.0". + License: Expat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff -Nru golang-github-pelletier-go-toml-1.9.0/debian/watch golang-github-pelletier-go-toml-1.9.4/debian/watch --- golang-github-pelletier-go-toml-1.9.0/debian/watch 2019-08-11 09:49:41.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/debian/watch 2021-10-20 08:43:36.000000000 +0000 @@ -1,4 +1,4 @@ -version=3 -opts=filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/go-toml-\$1\.tar\.gz/,\ -uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/\$1~\$2\$3/ \ - https://github.com/pelletier/go-toml/tags .*/v?(\d\S*)\.tar\.gz +version=4 +opts="filenamemangle=s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%@PACKAGE@-$1.tar.gz%,\ + uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/$1~$2$3/" \ + https://github.com/pelletier/go-toml/tags .*/v?(1\S*)\.tar\.gz debian diff -Nru golang-github-pelletier-go-toml-1.9.0/.github/dependabot.yml golang-github-pelletier-go-toml-1.9.4/.github/dependabot.yml --- golang-github-pelletier-go-toml-1.9.0/.github/dependabot.yml 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/.github/dependabot.yml 2021-09-06 01:38:35.000000000 +0000 @@ -0,0 +1,8 @@ +version: 2 +updates: +- package-ecosystem: gomod + directory: "/" + schedule: + interval: daily + time: "13:00" + open-pull-requests-limit: 10 diff -Nru golang-github-pelletier-go-toml-1.9.0/.github/ISSUE_TEMPLATE/bug_report.md golang-github-pelletier-go-toml-1.9.4/.github/ISSUE_TEMPLATE/bug_report.md --- golang-github-pelletier-go-toml-1.9.0/.github/ISSUE_TEMPLATE/bug_report.md 2021-03-26 00:57:38.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/.github/ISSUE_TEMPLATE/bug_report.md 2021-09-06 01:38:35.000000000 +0000 @@ -1,9 +1,18 @@ --- name: Bug report about: Create a report to help us improve - --- + + + **Describe the bug** A clear and concise description of what the bug is. @@ -14,7 +23,7 @@ A clear and concise description of what you expected to happen, if other than "should work". **Versions** - - go-toml: version (git sha) + - go-toml: version (or git sha) - go: version - operating system: e.g. macOS, Windows, Linux diff -Nru golang-github-pelletier-go-toml-1.9.0/.github/ISSUE_TEMPLATE/config.yml golang-github-pelletier-go-toml-1.9.4/.github/ISSUE_TEMPLATE/config.yml --- golang-github-pelletier-go-toml-1.9.0/.github/ISSUE_TEMPLATE/config.yml 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/.github/ISSUE_TEMPLATE/config.yml 2021-09-06 01:38:35.000000000 +0000 @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: Questions and discussions + url: https://github.com/pelletier/go-toml/discussions + about: Please ask and answer questions here. diff -Nru golang-github-pelletier-go-toml-1.9.0/LICENSE golang-github-pelletier-go-toml-1.9.4/LICENSE --- golang-github-pelletier-go-toml-1.9.0/LICENSE 2021-03-26 00:57:38.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/LICENSE 2021-09-06 01:38:35.000000000 +0000 @@ -1,3 +1,13 @@ +The bulk of github.com/pelletier/go-toml is distributed under the MIT license +(see below), with the exception of localtime.go and localtime.test.go. +Those two files have been copied over from Google's civil library at revision +ed46f5086358513cf8c25f8e3f022cb838a49d66, and are distributed under the Apache +2.0 license (see below). + + +github.com/pelletier/go-toml: + + The MIT License (MIT) Copyright (c) 2013 - 2021 Thomas Pelletier, Eric Anderton @@ -19,3 +29,219 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +localtime.go, localtime_test.go: + +Originals: + https://raw.githubusercontent.com/googleapis/google-cloud-go/ed46f5086358513cf8c25f8e3f022cb838a49d66/civil/civil.go + https://raw.githubusercontent.com/googleapis/google-cloud-go/ed46f5086358513cf8c25f8e3f022cb838a49d66/civil/civil_test.go +Changes: + * Renamed files from civil* to localtime*. + * Package changed from civil to toml. + * 'Local' prefix added to all structs. +License: + https://raw.githubusercontent.com/googleapis/google-cloud-go/ed46f5086358513cf8c25f8e3f022cb838a49d66/LICENSE + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff -Nru golang-github-pelletier-go-toml-1.9.0/localtime.go golang-github-pelletier-go-toml-1.9.4/localtime.go --- golang-github-pelletier-go-toml-1.9.0/localtime.go 2021-03-26 00:57:38.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/localtime.go 2021-09-06 01:38:35.000000000 +0000 @@ -1,6 +1,12 @@ // Implementation of TOML's local date/time. -// Copied over from https://github.com/googleapis/google-cloud-go/blob/master/civil/civil.go -// to avoid pulling all the Google dependencies. +// +// Copied over from Google's civil to avoid pulling all the Google dependencies. +// Originals: +// https://raw.githubusercontent.com/googleapis/google-cloud-go/ed46f5086358513cf8c25f8e3f022cb838a49d66/civil/civil.go +// Changes: +// * Renamed files from civil* to localtime*. +// * Package changed from civil to toml. +// * 'Local' prefix added to all structs. // // Copyright 2016 Google LLC // diff -Nru golang-github-pelletier-go-toml-1.9.0/localtime_test.go golang-github-pelletier-go-toml-1.9.4/localtime_test.go --- golang-github-pelletier-go-toml-1.9.0/localtime_test.go 2021-03-26 00:57:38.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/localtime_test.go 2021-09-06 01:38:35.000000000 +0000 @@ -1,3 +1,13 @@ +// Implementation of TOML's local date/time. +// +// Copied over from Google's civil to avoid pulling all the Google dependencies. +// Originals: +// https://raw.githubusercontent.com/googleapis/google-cloud-go/ed46f5086358513cf8c25f8e3f022cb838a49d66/civil/civil_test.go +// Changes: +// * Renamed files from civil* to localtime*. +// * Package changed from civil to toml. +// * 'Local' prefix added to all structs. +// // Copyright 2016 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); diff -Nru golang-github-pelletier-go-toml-1.9.0/marshal.go golang-github-pelletier-go-toml-1.9.4/marshal.go --- golang-github-pelletier-go-toml-1.9.0/marshal.go 2021-03-26 00:57:38.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/marshal.go 2021-09-06 01:38:35.000000000 +0000 @@ -258,11 +258,12 @@ w io.Writer encOpts annotation - line int - col int - order MarshalOrder - promoteAnon bool - indentation string + line int + col int + order MarshalOrder + promoteAnon bool + compactComments bool + indentation string } // NewEncoder returns a new encoder that writes to w. @@ -369,6 +370,12 @@ return e } +// CompactComments removes the new line before each comment in the tree. +func (e *Encoder) CompactComments(cc bool) *Encoder { + e.compactComments = cc + return e +} + func (e *Encoder) marshal(v interface{}) ([]byte, error) { // Check if indentation is valid for _, char := range e.indentation { @@ -408,7 +415,7 @@ } var buf bytes.Buffer - _, err = t.writeToOrdered(&buf, "", "", 0, e.arraysOneElementPerLine, e.order, e.indentation, false) + _, err = t.writeToOrdered(&buf, "", "", 0, e.arraysOneElementPerLine, e.order, e.indentation, e.compactComments, false) return buf.Bytes(), err } @@ -591,6 +598,7 @@ _, isTree := val.(*Tree) _, isTreeS := val.([]*Tree) if isTree || isTreeS { + e.line++ return val } diff -Nru golang-github-pelletier-go-toml-1.9.0/marshal_test.go golang-github-pelletier-go-toml-1.9.4/marshal_test.go --- golang-github-pelletier-go-toml-1.9.0/marshal_test.go 2021-03-26 00:57:38.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/marshal_test.go 2021-09-06 01:38:35.000000000 +0000 @@ -1476,6 +1476,47 @@ } } +func TestCompactComments(t *testing.T) { + expected := []byte(` +[first-section] + # comment for first-key + first-key = 1 + # comment for second-key + second-key = "value" + # comment for commented third-key + # third-key = [] + +[second-section] + # comment for first-key + first-key = 2 + # comment for second-key + second-key = "another value" + # comment for commented third-key + # third-key = ["value1", "value2"] +`) + type Settings struct { + FirstKey int `toml:"first-key" comment:"comment for first-key"` + SecondKey string `toml:"second-key" comment:"comment for second-key"` + ThirdKey []string `toml:"third-key" comment:"comment for commented third-key" commented:"true"` + } + type Config struct { + FirstSection Settings `toml:"first-section"` + SecondSection Settings `toml:"second-section"` + } + data := Config{ + FirstSection: Settings{1, "value", []string{}}, + SecondSection: Settings{2, "another value", []string{"value1", "value2"}}, + } + buf := new(bytes.Buffer) + if err := NewEncoder(buf).CompactComments(true).Encode(data); err != nil { + t.Fatal(err) + } + + if !bytes.Equal(expected, buf.Bytes()) { + t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, buf.Bytes()) + } +} + type mapsTestStruct struct { Simple map[string]string Paths map[string]string diff -Nru golang-github-pelletier-go-toml-1.9.0/README.md golang-github-pelletier-go-toml-1.9.4/README.md --- golang-github-pelletier-go-toml-1.9.0/README.md 2021-03-26 00:57:38.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/README.md 2021-09-06 01:38:35.000000000 +0000 @@ -12,6 +12,31 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/pelletier/go-toml)](https://goreportcard.com/report/github.com/pelletier/go-toml) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fpelletier%2Fgo-toml.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fpelletier%2Fgo-toml?ref=badge_shield) + +## Development status + +**ℹ️ Consider go-toml v2!** + +The next version of go-toml is in [active development][v2-dev], and +[nearing completion][v2-map]. + +Though technically in beta, v2 is already more tested, [fixes bugs][v1-bugs], +and [much faster][v2-bench]. If you only need reading and writing TOML documents +(majority of cases), those features are implemented and the API unlikely to +change. + +The remaining features (Document structure editing and tooling) will be added +shortly. While pull-requests are welcome on v1, no active development is +expected on it. When v2.0.0 is released, v1 will be deprecated. + +👉 [go-toml v2][v2] + +[v2]: https://github.com/pelletier/go-toml/tree/v2 +[v2-map]: https://github.com/pelletier/go-toml/discussions/506 +[v2-dev]: https://github.com/pelletier/go-toml/tree/v2 +[v1-bugs]: https://github.com/pelletier/go-toml/issues?q=is%3Aissue+is%3Aopen+label%3Av2-fixed +[v2-bench]: https://github.com/pelletier/go-toml/tree/v2#benchmarks + ## Features Go-toml provides the following features for using data parsed from TOML documents: @@ -109,7 +134,7 @@ ### Docker image -Those tools are also availble as a Docker image from +Those tools are also available as a Docker image from [dockerhub](https://hub.docker.com/r/pelletier/go-toml). For example, to use `tomljson`: @@ -148,4 +173,4 @@ ## License -The MIT License (MIT). Read [LICENSE](LICENSE). +The MIT License (MIT) + Apache 2.0. Read [LICENSE](LICENSE). diff -Nru golang-github-pelletier-go-toml-1.9.0/tomltree_write.go golang-github-pelletier-go-toml-1.9.4/tomltree_write.go --- golang-github-pelletier-go-toml-1.9.0/tomltree_write.go 2021-03-26 00:57:38.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/tomltree_write.go 2021-09-06 01:38:35.000000000 +0000 @@ -226,7 +226,9 @@ } func getTreeArrayLine(trees []*Tree) (line int) { - // get lowest line number that is not 0 + // Prevent returning 0 for empty trees + line = int(^uint(0) >> 1) + // get lowest line number >= 0 for _, tv := range trees { if tv.position.Line < line || line == 0 { line = tv.position.Line @@ -315,10 +317,10 @@ } func (t *Tree) writeTo(w io.Writer, indent, keyspace string, bytesCount int64, arraysOneElementPerLine bool) (int64, error) { - return t.writeToOrdered(w, indent, keyspace, bytesCount, arraysOneElementPerLine, OrderAlphabetical, " ", false) + return t.writeToOrdered(w, indent, keyspace, bytesCount, arraysOneElementPerLine, OrderAlphabetical, " ", false, false) } -func (t *Tree) writeToOrdered(w io.Writer, indent, keyspace string, bytesCount int64, arraysOneElementPerLine bool, ord MarshalOrder, indentString string, parentCommented bool) (int64, error) { +func (t *Tree) writeToOrdered(w io.Writer, indent, keyspace string, bytesCount int64, arraysOneElementPerLine bool, ord MarshalOrder, indentString string, compactComments, parentCommented bool) (int64, error) { var orderedVals []sortNode switch ord { @@ -368,7 +370,7 @@ if err != nil { return bytesCount, err } - bytesCount, err = node.writeToOrdered(w, indent+indentString, combinedKey, bytesCount, arraysOneElementPerLine, ord, indentString, parentCommented || t.commented || tv.commented) + bytesCount, err = node.writeToOrdered(w, indent+indentString, combinedKey, bytesCount, arraysOneElementPerLine, ord, indentString, compactComments, parentCommented || t.commented || tv.commented) if err != nil { return bytesCount, err } @@ -384,7 +386,7 @@ return bytesCount, err } - bytesCount, err = subTree.writeToOrdered(w, indent+indentString, combinedKey, bytesCount, arraysOneElementPerLine, ord, indentString, parentCommented || t.commented || subTree.commented) + bytesCount, err = subTree.writeToOrdered(w, indent+indentString, combinedKey, bytesCount, arraysOneElementPerLine, ord, indentString, compactComments, parentCommented || t.commented || subTree.commented) if err != nil { return bytesCount, err } @@ -412,7 +414,14 @@ if strings.HasPrefix(comment, "#") { start = "" } - writtenBytesCountComment, errc := writeStrings(w, "\n", indent, start, comment, "\n") + if !compactComments { + writtenBytesCountComment, errc := writeStrings(w, "\n") + bytesCount += int64(writtenBytesCountComment) + if errc != nil { + return bytesCount, errc + } + } + writtenBytesCountComment, errc := writeStrings(w, indent, start, comment, "\n") bytesCount += int64(writtenBytesCountComment) if errc != nil { return bytesCount, errc diff -Nru golang-github-pelletier-go-toml-1.9.0/tomltree_write_test.go golang-github-pelletier-go-toml-1.9.4/tomltree_write_test.go --- golang-github-pelletier-go-toml-1.9.0/tomltree_write_test.go 2021-03-26 00:57:38.000000000 +0000 +++ golang-github-pelletier-go-toml-1.9.4/tomltree_write_test.go 2021-09-06 01:38:35.000000000 +0000 @@ -364,6 +364,55 @@ } } +func TestOrderedEmptyTrees(t *testing.T) { + type val struct { + Key string `toml:"key"` + } + type structure struct { + First val `toml:"first"` + Empty []val `toml:"empty"` + } + input := structure{First: val{Key: "value"}} + buf := new(bytes.Buffer) + err := NewEncoder(buf).Order(OrderPreserve).Encode(input) + if err != nil { + t.Fatal("failed to encode input") + } + expected := ` +[first] + key = "value" +` + if expected != buf.String() { + t.Fatal("expected and encoded body aren't equal: ", expected, buf.String()) + } +} + +func TestOrderedNonIncreasedLine(t *testing.T) { + type NiceMap map[string]string + type Manifest struct { + NiceMap `toml:"dependencies"` + Build struct { + BuildCommand string `toml:"build-command"` + } `toml:"build"` + } + + test := &Manifest{} + test.Build.BuildCommand = "test" + buf := new(bytes.Buffer) + if err := NewEncoder(buf).Order(OrderPreserve).Encode(test); err != nil { + panic(err) + } + expected := ` +[dependencies] + +[build] + build-command = "test" +` + if expected != buf.String() { + t.Fatal("expected and encoded body aren't equal: ", expected, buf.String()) + } +} + func TestIssue290(t *testing.T) { tomlString := `[table]