Skip to content

Commit

Permalink
fix bug in markup parser whenever the same attribute appears twice
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiEven committed Jan 28, 2024
1 parent b9f6f20 commit e293537
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion markup/line_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (lineParser *LineParser) buildAttributesFromMarkers(markers []attributeMark
}

matchedOpenMarker := unclosedMarkers[matchedOpenMarkerIndex]
unclosedMarkers = slices.Delete(unclosedMarkers, matchedOpenMarkerIndex, matchedOpenMarkerIndex)
unclosedMarkers = slices.Delete(unclosedMarkers, matchedOpenMarkerIndex, matchedOpenMarkerIndex+1)

length := marker.position - matchedOpenMarker.position
attribute := Attribute{
Expand Down
22 changes: 22 additions & 0 deletions markup/line_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ func TestLineParser(t *testing.T) {
},
},
},
"attribute appearing twice": {
input: `Oh, [wave]hello[/wave] [wave](twice)[/wave] there!`,
expectedResult: &ParseResult{
Text: `Oh, hello (twice) there!`,
Attributes: []Attribute{
{
Name: "wave",
Position: 4,
SourcePosition: 4,
Length: 5,
Properties: map[string]Value{},
},
{
Name: "wave",
Position: 10,
SourcePosition: 23,
Length: 7,
Properties: map[string]Value{},
},
},
},
},
"overlapping attributes": {
input: `Oh, [wave]hello [bounce]there![/bounce][/wave]`,
expectedResult: &ParseResult{
Expand Down

0 comments on commit e293537

Please sign in to comment.