From e293537428fe9299c190ed1331def040d4399b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Even?= Date: Sun, 28 Jan 2024 22:59:13 +0000 Subject: [PATCH] fix bug in markup parser whenever the same attribute appears twice --- markup/line_parser.go | 2 +- markup/line_parser_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/markup/line_parser.go b/markup/line_parser.go index fb6119b..dada900 100644 --- a/markup/line_parser.go +++ b/markup/line_parser.go @@ -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{ diff --git a/markup/line_parser_test.go b/markup/line_parser_test.go index d21a005..f091c10 100644 --- a/markup/line_parser_test.go +++ b/markup/line_parser_test.go @@ -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{