Skip to content

Commit

Permalink
remove hue from js links
Browse files Browse the repository at this point in the history
  • Loading branch information
elferherrera committed Jun 16, 2022
1 parent a6e2b11 commit a9fd83c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import (
// A Linker is used to correct the links found in the response body
// It will add the prefix when a regex match is found
type Linker struct {
quoted_reg *regexp.Regexp
quoted_reg *regexp.Regexp
hue_base_url *regexp.Regexp
}

func new_linker(paths string) Linker {
quoted := `([='"])(` + paths + ")"
hue_base := `window.HUE_BASE_URL\s*[+]\s*'/hue'\s*[+]`

linker := Linker{
quoted_reg: regexp.MustCompile(quoted),
quoted_reg: regexp.MustCompile(quoted),
hue_base_url: regexp.MustCompile(hue_base),
}

return linker
Expand All @@ -25,5 +28,7 @@ func (l *Linker) replace(file []byte, service_prefix string) []byte {
prefix := "$1" + strings.TrimSuffix(service_prefix, "/") + "$2"
replaced := l.quoted_reg.ReplaceAll(file, []byte(prefix))

replaced = l.hue_base_url.ReplaceAll(replaced, []byte("window.HUE_BASE_URL +"))

return replaced
}
8 changes: 8 additions & 0 deletions linker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ func TestLinker(t *testing.T) {
`<link href="/user/user@comp/static/desktop/css/roboto.895233d7bf84.css" rel="stylesheet">
<link href="/user/user@comp/static/desktop/ext/css/font-awesome.min.bf0c425cdb73.css" rel="stylesheet">`,
},
{
`link = window.HUE_BASE_URL + '/hue' + link;`,
`link = window.HUE_BASE_URL + link;`,
},
{
`link = window.HUE_BASE_URL+'/hue'+link;`,
`link = window.HUE_BASE_URL +link;`,
},
}

for _, tc := range cases {
Expand Down

0 comments on commit a9fd83c

Please sign in to comment.