From e8958efd6690c5c83d6d14b1b512140b51808ddc Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Tue, 20 Dec 2022 12:45:23 +0100
Subject: [PATCH] fix: remove attributes that are set

---
 engine/engine.go      |  4 +++-
 engine/engine_test.go | 13 +++++++++++--
 go.mod                |  5 ++++-
 go.sum                |  7 +++++++
 4 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/engine/engine.go b/engine/engine.go
index 8da38d5..4365fdd 100644
--- a/engine/engine.go
+++ b/engine/engine.go
@@ -200,7 +200,7 @@ func (e *Engine) processRepeat(node *html.Node, attr html.Attribute) *Engine {
 			errors = runNode(node, data, key, item, nextSibling, parent)
 
 		}
-		
+
 	default:
 		e.errors = append(e.errors, &UnsupportedTypeError{Message: "Unsupported iterator type", NodeType: node.Type})
 	}
@@ -626,6 +626,8 @@ func (e *Engine) processAttributes(node *html.Node, attr html.Attribute) *Engine
 			cVal = val.(string)
 		}
 
+		node.Attr = removeAttribute(node.Attr, key)
+
 		node.Attr = append(node.Attr, html.Attribute{
 			Key: key,
 			Val: cVal,
diff --git a/engine/engine_test.go b/engine/engine_test.go
index 222fe6c..c788495 100644
--- a/engine/engine_test.go
+++ b/engine/engine_test.go
@@ -1,10 +1,11 @@
 package engine
 
 import (
-	"github.com/stretchr/testify/assert"
-	"golang.org/x/net/html"
 	"strings"
 	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"golang.org/x/net/html"
 )
 
 func TestNewEngine(t *testing.T) {
@@ -56,6 +57,14 @@ func TestProcessHtml(t *testing.T) {
 		expected  string
 		data      map[any]any
 	}{
+		{
+			html:      `<!DOCTYPE html><html lang="en" data-attributes="lang path:lang"><head><body>`,
+			hasErrors: false,
+			expected:  `<!DOCTYPE html><html lang="en"><head></head><body></body></html>`,
+			data: map[any]any{
+				"lang": "en",
+			},
+		},
 		{
 			html:      `<div data-test="test"></div>`,
 			hasErrors: false,
diff --git a/go.mod b/go.mod
index 481e4b5..83d3a11 100644
--- a/go.mod
+++ b/go.mod
@@ -3,13 +3,16 @@ module gitlab.schukai.com/oss/libraries/go/markup/html
 go 1.19
 
 require (
+	github.com/andybalholm/cascadia v1.3.1
 	github.com/stretchr/testify v1.8.1
+	gitlab.schukai.com/oss/libraries/go/utilities/data.git v0.2.0
 	golang.org/x/net v0.2.0
 )
 
 require (
-	github.com/andybalholm/cascadia v1.3.1 // indirect
 	github.com/davecgh/go-spew v1.1.1 // indirect
 	github.com/pmezard/go-difflib v1.0.0 // indirect
+	github.com/volker-schukai/tokenizer v1.0.0 // indirect
+	gitlab.schukai.com/oss/libraries/go/utilities/pathfinder v0.4.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
 )
diff --git a/go.sum b/go.sum
index efab647..f879614 100644
--- a/go.sum
+++ b/go.sum
@@ -8,10 +8,17 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+github.com/volker-schukai/tokenizer v1.0.0 h1:wF4haFoCodq7lgAk8c+th/DZmpFpL2WVD8wDzAGU1mA=
+github.com/volker-schukai/tokenizer v1.0.0/go.mod h1:LPw7lLIxUnZgeg96818N7IvwLE1x8ya31J/Aa0aCq9M=
+gitlab.schukai.com/oss/libraries/go/utilities/data.git v0.2.0 h1:JVxMHiA8zFVjJDhNl65XeYrhdMkzB+5dyrBUEZ982WU=
+gitlab.schukai.com/oss/libraries/go/utilities/data.git v0.2.0/go.mod h1:BsR4Y9jsvISplkW6UoLFRGxQX69/AUmP1SXRwWhx31o=
+gitlab.schukai.com/oss/libraries/go/utilities/pathfinder v0.4.0 h1:eAEsq3lsHwMe5Zz71vNab5csPtp8S+i5zFPmNnDPFDg=
+gitlab.schukai.com/oss/libraries/go/utilities/pathfinder v0.4.0/go.mod h1:UvdD4NAf3gLKYafabJD7e9ZCOetzM9JZ9y4GkZukPVU=
 golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
 golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
-- 
GitLab