Skip to content
This repository has been archived by the owner on Dec 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #20 from 18F/convert-foo-bar
Browse files Browse the repository at this point in the history
Converting foo to bar in path
  • Loading branch information
jthomp13 authored Sep 9, 2019
2 parents c33759f + 32f3065 commit 0e46409
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"html"
"net/http"
"os"
"regexp"

log "github.com/sirupsen/logrus"
)
Expand All @@ -15,6 +16,8 @@ func init() {
}

func helloHtml(path string) string {
re := regexp.MustCompile(`(?i)foo`)
path = re.ReplaceAllString(path, "bar")
return fmt.Sprintf("<h1>Salutations AMPD from Go,</h1>\n<p>You've requested: %s</p>\n", html.EscapeString(path))
}

Expand Down
8 changes: 8 additions & 0 deletions src/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ func TestJavaScriptInjection(t *testing.T) {
t.Fatal("JavaScript injection attack")
}
}

func TestConvertFoo(t *testing.T) {
path := "/foo/bar"
text := helloHtml(path)
if strings.Contains(text, "foo") {
t.Fatal("'foo' in path")
}
}

0 comments on commit 0e46409

Please sign in to comment.