Skip to content

Commit

Permalink
Remove one colon check for well-formed edge tags (#2729)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannzhou authored Jun 11, 2024
1 parent d789322 commit 028515c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
18 changes: 1 addition & 17 deletions internal/datastreams/pathway.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,9 @@ import (

var hashableEdgeTags = map[string]struct{}{"event_type": {}, "exchange": {}, "group": {}, "topic": {}, "type": {}, "direction": {}}

func isValidArn(arn string) bool {
separators := strings.Count(arn, ":")
if separators < 5 {
return false
}
if strings.HasPrefix(arn, "arn:") {
return true
}
return false
}

func isWellFormedEdgeTag(t string) bool {
if i := strings.IndexByte(t, ':'); i != -1 {
if j := strings.LastIndexByte(t, ':'); j == i {
if _, exists := hashableEdgeTags[t[:i]]; exists {
return true
}
}
if t[:i] == "topic" && isValidArn(t) {
if _, exists := hashableEdgeTags[t[:i]]; exists {
return true
}
}
Expand Down
7 changes: 4 additions & 3 deletions internal/datastreams/pathway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ func TestPathway(t *testing.T) {
{"dog:bark", false},
{"type:", true},
{"type:dog", true},
{"type::dog", false},
{"type:d:o:g", false},
{"type::", false},
{"type::dog", true},
{"type:d:o:g", true},
{"type::", true},
{":", false},
{"topic:arn:aws:sns:us-east-1:727006795293:dsm-dev-sns-topic", true},
} {
assert.Equal(t, isWellFormedEdgeTag(tc.s), tc.b)
}
Expand Down

0 comments on commit 028515c

Please sign in to comment.