Skip to content

Commit

Permalink
fix:adding more than 10 images will cause loop infinite (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
0fv authored Mar 31, 2024
1 parent 3dde65b commit 28214b5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Template.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func (t *Template) replaceSingleParams(xnode *xmlNode, triggerParamOnly bool) {
return
}
// Prefix check
if !bytes.Contains(n.Content, []byte(p.PlaceholderPrefix())) {
if !n.ContentHasPrefix(p.PlaceholderPrefix()) {
return
}
// Trigger: does placeholder have trigger
Expand Down
60 changes: 60 additions & 0 deletions t.docx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,66 @@ func TestPlaceholders(t *testing.T) {
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
{
Path: "images/avatar-3.png",
Width: 25,
Height: 25,
},
},
}

Expand Down
9 changes: 9 additions & 0 deletions xml.node.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ type xmlNode struct {
isDeleted bool
}

func (xnode xmlNode) ContentHasPrefix(str string) bool {
splitContent :=bytes.Split(xnode.Content, []byte(str))
if len(splitContent) == 1{
return false
}
contentSuffix := splitContent[1]
return bytes.HasPrefix(contentSuffix, []byte{'.'}) || bytes.HasPrefix(contentSuffix, []byte{'}', '}'}) || bytes.HasPrefix(contentSuffix, []byte{' '})
}

// UnmarshalXML ..
func (xnode *xmlNode) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// n.Attrs = start.Attr
Expand Down

0 comments on commit 28214b5

Please sign in to comment.