Skip to content

Commit

Permalink
Merge pull request #1390 from gavin-ts/improve-tooltip-url-check
Browse files Browse the repository at this point in the history
compiler: improve tooltip url check
  • Loading branch information
gavin-ts authored Jun 9, 2023
2 parents 5c49761 + 2f10721 commit f561b83
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

#### Improvements 🧹

- Improves compiler's tooltip URL check. [#1390](https://github.com/terrastruct/d2/pull/1390)

#### Bugfixes ⛑️
4 changes: 2 additions & 2 deletions d2compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) {
}

if attrs.Link != nil && attrs.Tooltip != nil {
_, err := url.ParseRequestURI(attrs.Tooltip.Value)
if err == nil {
u, err := url.ParseRequestURI(attrs.Tooltip.Value)
if err == nil && u.Host != "" {
c.errorf(scalar, "Tooltip cannot be set to URL when link is also set (for security)")
}
}
Expand Down
5 changes: 5 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,11 @@ x -> y: {
text: `x: {link: https://not-google.com; tooltip: https://google.com}`,
expErr: `d2/testdata/d2compiler/TestCompile/no_url_link_and_url_tooltip_concurrently.d2:1:44: Tooltip cannot be set to URL when link is also set (for security)`,
},
{
name: "url_link_non_url_tooltip_ok",
text: `x: {link: https://not-google.com; tooltip: note: url.ParseRequestURI might see this as a URL}`,
expErr: ``,
},
{
name: "url_link_and_not_url_tooltip_concurrently",
text: `x: {link: https://google.com; tooltip: hello world}`,
Expand Down
184 changes: 184 additions & 0 deletions testdata/d2compiler/TestCompile/url_link_non_url_tooltip_ok.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f561b83

Please sign in to comment.