diffparser
diffparser copied to clipboard
Parser fails with `"A FROM_FILE line ('---') must be directly followed by a TO_FILE line ('+++')"` when diff contains YAML document separators
When parsing a git diff that contains YAML document separators (---) as part of the file content (not as part of the diff header), the parser throws:
A FROM_FILE line ('---') must be directly followed by a TO_FILE line ('+++')!
This occurs when the YAML file has multi-document content and one of those document boundaries is added in the diff.
Minimal Example
diff --git a/example.yaml b/example.yaml
index 1111111..2222222 100644
--- a/example.yaml
+++ b/example.yaml
@@ -8,9 +8,9 @@ metadata:
name: "Example"
description: "Example description"
tags:
- - tag-old
+ - tag-new
spec:
key1: value1
- key2: value2
----
+ key2: value2
+---
apiVersion: example.io/v1
kind: Component
metadata:
@@ -22,6 +22,24 @@ spec:
dependsOn: []
type: library
lifecycle: production
owner: example-owner
+---
+apiVersion: example.io/v1
+kind: Component
+metadata:
+ name: "AnotherExample"
+ description: "Another doc added"
+ tags:
+ - tag1
+ - tag2
+spec:
+ dependsOn: []
+ type: library
+ lifecycle: production
+ owner: example-owner
Expected Behavior
The parser should treat --- as a line addition (content) and not confuse it with the diff header.
Actual Behavior
Throws:
A FROM_FILE line ('---') must be directly followed by a TO_FILE line ('+++')!
Notes
- This happens consistently when the diff adds a YAML document separator.
- Verified on version:
io.reflectoring.diffparser:diffparser:1.4