Skip to content

Commit

Permalink
Trims leading space, or it gets into a loop where every time it runs …
Browse files Browse the repository at this point in the history
…an additional space is added

Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
Daniel Mikusa committed Oct 4, 2021
1 parent 7b22fdb commit 78f10e6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions carton/buildpack_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions carton/package_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion carton/package_dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down

0 comments on commit 78f10e6

Please sign in to comment.