diff --git a/carton/buildpack_dependency.go b/carton/buildpack_dependency.go index a2f4770..6e901a4 100644 --- a/carton/buildpack_dependency.go +++ b/carton/buildpack_dependency.go @@ -72,8 +72,8 @@ func (b BuildpackDependency) Update(options ...Option) { // save any leading comments, this is to preserve license headers // inline comments will be lost comments := []byte{} - for _, line := range bytes.SplitAfter(c, []byte("\n")) { - if bytes.HasPrefix(line, []byte("#")) || len(bytes.TrimSpace(line)) == 0 { + for i, line := range bytes.SplitAfter(c, []byte("\n")) { + if bytes.HasPrefix(line, []byte("#")) || (i > 0 && len(bytes.TrimSpace(line)) == 0) { comments = append(comments, line...) } else { break // stop on first comment diff --git a/carton/package_dependency.go b/carton/package_dependency.go index 8b9bd9b..5db0a38 100644 --- a/carton/package_dependency.go +++ b/carton/package_dependency.go @@ -148,8 +148,8 @@ func updateFile(cfgPath string, f func(md map[string]interface{})) error { // save any leading comments, this is to preserve license headers // inline comments will be lost comments := []byte{} - for _, line := range bytes.SplitAfter(c, []byte("\n")) { - if bytes.HasPrefix(line, []byte("#")) || len(bytes.TrimSpace(line)) == 0 { + for i, line := range bytes.SplitAfter(c, []byte("\n")) { + if bytes.HasPrefix(line, []byte("#")) || (i > 0 && len(bytes.TrimSpace(line)) == 0) { comments = append(comments, line...) } else { break // stop on first comment diff --git a/carton/package_dependency_test.go b/carton/package_dependency_test.go index 88ab555..6b47e93 100644 --- a/carton/package_dependency_test.go +++ b/carton/package_dependency_test.go @@ -110,7 +110,8 @@ include-files = [ }) it("updates paketo-buildpacks dependency id partial id", func() { - Expect(ioutil.WriteFile(path, []byte(`[[order]] + Expect(ioutil.WriteFile(path, []byte(` +[[order]] group = [ { id = "paketo-buildpacks/test-1", version="test-version-1" }, { id = "paketo-buildpacks/test-2", version="test-version-2" },