fix: Allow patches with empty files with multiple newlines or comments (#5771)

* fix: Add test, when an empty patch file is given, it should not fail

* fix: Add code so there's no error given if an empty file is given as a patch

* chore: Generate plugin with pluginator

* chore: fix tests

Signed-off-by: Julio Chana <julio.chana@lokalise.com>

* Add t.helper() at start of test function

Signed-off-by: Julio Chana <julio.chana@lokalise.com>

---------

Signed-off-by: Julio Chana <julio.chana@lokalise.com>
This commit is contained in:
Julio Chana
2025-03-17 03:15:48 +01:00
committed by GitHub
parent 2643c51364
commit 31b37540e3
3 changed files with 57 additions and 4 deletions

View File

@@ -56,8 +56,9 @@ func (p *PatchTransformerPlugin) Config(h *resmap.PluginHelpers, c []byte) error
patchesSM, errSM := h.ResmapFactory().RF().SliceFromBytes([]byte(p.patchText))
patchesJson, errJson := jsonPatchFromBytes([]byte(p.patchText))
if (errSM == nil && errJson == nil) ||
(patchesSM != nil && patchesJson != nil) {
if ((errSM == nil && errJson == nil) ||
(patchesSM != nil && patchesJson != nil)) &&
(len(patchesSM) > 0 && len(patchesJson) > 0) {
return fmt.Errorf(
"illegally qualifies as both an SM and JSON patch: %s",
p.patchSource)