Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailer-looking lines can cause the parsing to abort early #38

Open
apricote opened this issue Nov 15, 2024 · 0 comments
Open

Trailer-looking lines can cause the parsing to abort early #38

apricote opened this issue Nov 15, 2024 · 0 comments

Comments

@apricote
Copy link

If a commit includes some lines that look like trailers but were not intended as ones, this can throw off the parsing. This causes later actual trailers to be ignored.

As far as I could tell the conventional commit spec does not specify that only actual trailers may look like trailers.

I tried to make the changes in machine.go.rl myself but did not get anywhere.

Reproduction

Example commit that causes problems:

feat: some thing (hz/fl!144)

Fixes #15                             <-- Intepreted as a footer/trailer

Lorem ipsum dolor sit amet

BREAKING CHANGE: Some explanation
Reviewed-by: XX <[email protected]>

I would expect the following ConventionalCommit for this:

commit := ConventionalCommit{
	Type:        "feat",
	Description: ""
	Scope:       nil,
	Exclamation: false,
	Body:       pointer.Pointer("Fixes #15\n\nLorem ipsum dolor sit amet"),
	Footers: map[string][]string{
		"breaking-change": []string{"Some explanation"},
		"reviewed-by":     []string{"XX <[email protected]>"},
        },
}

Test Case

func Example_fake_trailer() {
	i := []byte(`feat: some thing (hz/fl!144)

Fixes #15

Lorem ipsum dolor sit amet

BREAKING CHANGE: Some explanation
Reviewed-by: XX <[email protected]>`)
	m, e := NewMachine().Parse(i)
	output(m)
	fmt.Println(e)
	// Output:
	// (*conventionalcommits.ConventionalCommit)({
	//  Type: (string) (len=4) "feat",
	//  Description: (string) (len=22) "some thing (hz/fl!144)",
	//  Scope: (*string)(<nil>),
	//  Exclamation: (bool) false,
	//  Body: (*string)((len=37) "Fixes #15\n\nLorem ipsum dolor sit amet"),
	//  Footers: (map[string][]string) (len=2) {
	//   (string) (len=15) "breaking-change": ([]string) (len=1) {
	//    (string) (len=16) "Some explanation"
	//   },
	//   (string) (len=11) "reviewed-by": ([]string) (len=1) {
	//    (string) (len=19) "XX <[email protected]>"
	//   }
	//  },
	//  TypeConfig: (conventionalcommits.TypeConfig) 0
	// })
	// nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant