Skip to content

Commit

Permalink
Better documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed May 18, 2023
1 parent a639c04 commit 78415da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ The goada library provides support for the WHATWG URL standard in Go.
### Examples

```Go
url, nil := New("https:// www.GOoglé.com")
fmt.Println(url.Href()) // "https://www.xn--googl-fsa.com/"
url, nil := New("https:// www.GOoglé.com/./path/../path2/")
fmt.Println(url.Href()) // "https://www.xn--googl-fsa.com/path2/"
```

The standard `net/url` `Parse` function would refuse to parse the URL `"https:// www.GOoglé.com"` because it
contains a tabulation character. Even if we remove the tabulation character, it would still parse it to an incorrect
string as per the WHATGL URL standard (`https://www.GOogl%C3%A9.com`).
The standard `net/url` `Parse` function from the Go runtime refuses to parse the URL `"https:// www.GOoglé.com/./path/../path2/"` because it
contains a tabulation character. Even if we remove the tabulation character, it still parses it to an incorrect
string as per the WHATGW URL standard (`https://www.GOogl%C3%A9.com/./path/../path2/`). That is, if fails to normalize the domain name, and it does not process the path string.

### Usage

Expand Down
9 changes: 5 additions & 4 deletions goada_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ func BenchmarkSillyAda(b *testing.B) {
}

func TestStandard(t *testing.T) {
s1 := "https:// www.GOoglé.com"
s1 := "https:// www.GOoglé.com/./path/../path2/"
url, err := New(s1)
if err != nil {
t.Error("Expected no error")
}
fmt.Println(url.Href())
if strings.Compare(url.Href(), "https://www.xn--googl-fsa.com/") != 0 {
if strings.Compare(url.Href(), "https://www.xn--googl-fsa.com/path2/") != 0 {
t.Error("Expected normalized url")
}
url.Free()
}

func TestStandardGP(t *testing.T) {
Expand All @@ -89,13 +90,13 @@ func TestStandardGP(t *testing.T) {
if err == nil {
t.Error("Go url should fail")
}
s2 := "https://www.GOoglé.com"
s2 := "https://www.GOoglé.com/./path/../path2/"
url, err2 := url.Parse(s2)
if err2 != nil {
t.Error("Go url should hot fail")
}
fmt.Println(url.String())
if strings.Compare(url.String(), "https://www.GOogl%C3%A9.com") != 0 {
if strings.Compare(url.String(), "https://www.GOogl%C3%A9.com/./path/../path2/") != 0 {
t.Error("Expected invalid normalized url")
}
}

0 comments on commit 78415da

Please sign in to comment.