Skip to content

Commit

Permalink
fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsuh05 committed Sep 17, 2024
1 parent 181634e commit 92ea220
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions d2compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,16 +587,6 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) {
attrs.Link = &d2graph.Scalar{}
attrs.Link.Value = scalar.ScalarString()
attrs.Link.MapKey = f.LastPrimaryKey()

if attrs.Label.Value == "" {
attrs.Label.Value = attrs.Link.Value
} else {
// this works because the Label attribute is set before the Link attribute
u, err := url.ParseRequestURI(attrs.Label.Value)
if err == nil && u.Host != "" {
c.errorf(f.Primary_.Value, "Label cannot be set to URL when link is also set (for security)")
}
}
case "direction":
dirs := []string{"up", "down", "right", "left"}
if !go2.Contains(dirs, scalar.ScalarString()) {
Expand Down Expand Up @@ -844,6 +834,19 @@ func (c *compiler) compileEdgeField(edge *d2graph.Edge, f *d2ir.Field) {
_, isReserved := d2ast.SimpleReservedKeywords[keyword]
if isReserved {
c.compileReserved(&edge.Attributes, f)

if f.Name != "link" {
return
}

if edge.Label.Value == "" {
edge.Label.Value = edge.Link.Value
} else {
u, err := url.ParseRequestURI(edge.Label.Value)
if err == nil && u.Host != "" {
c.errorf(f.Primary_.Value, "Label cannot be set to URL when link is also set (for security)")
}
}
return
} else if f.Name == "style" {
if f.Map() == nil {
Expand Down

0 comments on commit 92ea220

Please sign in to comment.