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

Commit

Permalink
Ungx-ed commit d9f2bafa45693db2388544097089b3c7a5182110
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe authored and Travis CI User committed Mar 23, 2019
1 parent f34757c commit 63891ed
Show file tree
Hide file tree
Showing 27 changed files with 143 additions and 1,769 deletions.
2 changes: 1 addition & 1 deletion core/corehttp/ipns_hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
core "github.com/ipsn/go-ipfs/core"
namesys "github.com/ipsn/go-ipfs/namesys"

isd "github.com/gxed/go-is-domain"
nsopts "github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/interface-go-ipfs-core/options/namesys"
isd "github.com/ipsn/go-ipfs/gxlibs/github.com/jbenet/go-is-domain"
)

// IPNSHostnameOption rewrites an incoming request if its Host: header contains
Expand Down
18 changes: 18 additions & 0 deletions gxlibs/github.com/jbenet/go-is-domain/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
os:
- linux

language: go

go:
- 1.12.x

env:
GO111MODULE=on

cache:
directories:
- $GOPATH/pkg/mod
- /home/travis/.cache/go-build

notifications:
email: false
29 changes: 29 additions & 0 deletions gxlibs/github.com/jbenet/go-is-domain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# go-is-domain

This package is dedicated to [@whyrusleeping](https://github.com/whyrusleeping).

Docs: https://godoc.org/github.com/jbenet/go-is-domain


Check whether something is a domain.


```Go

import (
isd "github.com/jbenet/go-is-domain"
)

isd.IsDomain("foo.com") // true
isd.IsDomain("foo.bar.com.") // true
isd.IsDomain("foo.bar.baz") // false

```

MIT Licensed

## Updating TLDs

To update non-extended TLDs, IANA publishes, you can retrieve them from [data.iana.org](https://data.iana.org/TLD/tlds-alpha-by-domain.txt).

After retrieving the updated list, enter them into the file `tlds-alpha-by-domain.txt`. In order to update the `TLDs` map in `tlds.go`, you can run the `gen.sh` script which will generate the contents of a `string -> bool` map. After that, you'll want to replace the contents of the existing `TLDs` map, with the one that was generated and stored in `formatted_tlds.txt`
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Package isdomain package allows users to check whether strings represent domain names.
import (
isd "github.com/jbenet/go-is-domain"
isd "github.com/ipsn/go-ipfs/gxlibs/github.com/jbenet/go-is-domain"
)
isd.IsDomain("foo.com") // true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package isdomain
import "regexp"

// DomainRegexpStr is a regular expression string to validate domains.
const DomainRegexpStr = "^([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,}$"
const DomainRegexpStr = "^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*$"

var domainRegexp *regexp.Regexp

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package isdomain

import "strings"
import (
"strings"
)

//go:generate bash regenerate-tlds.sh

Expand Down Expand Up @@ -33,14 +35,20 @@ func IsDomain(s string) bool {
if strings.HasSuffix(s, ".") {
s = s[:len(s)-1]
}

split := strings.Split(s, ".")
tld := split[len(split)-1]

// Need a TLD and a domain.
if len(split) < 2 {
return false
}

// Check the TLD
tld := split[len(split)-1]
if !IsTLD(tld) {
return false
}

// Check the domain.
s = strings.ToLower(s)
return domainRegexp.MatchString(s)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ func TestBasic(t *testing.T) {
"com": false, // yeah yeah...
".": false, // yeah yeah...
"..": false,
".com": false,
".com.": false,
"com.": false,
"com..": false,
".foo.com.": false,
".foo.com": false,
"fo o.com": false,
Expand All @@ -19,6 +23,9 @@ func TestBasic(t *testing.T) {
"fjdoisajfdiosafdsa8fd8saf8dsa8fdsafdsa-fd-sa-fd-saf-dsa.onion": true,
"a.b.c.d.e.f.g.h.i.j.k.l.museum": true,
"a.b.c.d.e.f.g.h.i.j.k.l": false,
"_dnslink.example.com": false,
"example._dnslink.com": false,
"example.com._dnslink": false,
}

for d, ok := range cases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"language": "go",
"license": "MIT",
"name": "go-is-domain",
"version": "1.0.1"
"version": "1.0.2"
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ done >> $out
echo '}' >> $out

gofmt -w $out


Loading

0 comments on commit 63891ed

Please sign in to comment.