Skip to content

Commit

Permalink
tools: include IANA TLD URL in new gtld updates. (#1817)
Browse files Browse the repository at this point in the history
This commit updates the `tools/newgtlds.go` tooling to include a comment
line with the gTLD's IANA registry URL for each gTLD.

E.g. for the tld `aaa`, includes a comment line:
`// https://www.iana.org/domains/root/db/aaa.html`
  • Loading branch information
cpu authored Aug 9, 2023
1 parent ae888fa commit c0a861f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
24 changes: 18 additions & 6 deletions tools/newgtlds.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"
"text/template"
Expand All @@ -25,6 +26,8 @@ const (
// in the ICP-3 Root - including new ccTLDs, EBRERO gTLDS or things not in
// the JSON File above that should be included in the PSL. Note: UPPERCASE
IANA_TLDS_TXT_URL = "http://data.iana.org/TLD/tlds-alpha-by-domain.txt"
// IANA_TLD_URL_BASE is the base URL for IANA domain information pages.
IANA_TLD_URL_BASE = "https://www.iana.org/domains/root/db"
// PSL_GTLDS_SECTION_HEADER marks the start of the newGTLDs section of the
// overall public suffix dat file.
PSL_GTLDS_SECTION_HEADER = "// newGTLDs"
Expand Down Expand Up @@ -128,13 +131,13 @@ func (e *pslEntry) normalize() {
//
// If the registry operator field is empty the comment will be of the form:
//
// '// <ALabel>'
// '// https://www.iana.org/domains/root/db/<ALabel>.html'
// // <ALabel>
// // https://www.iana.org/domains/root/db/<ALabel>.html
//
// If the registry operator field is not empty the comment will be of the form:
//
// '// <ALabel> : <RegistryOperator>'
// '// https://www.iana.org/domains/root/db/<ALabel>.html'
// // <ALabel> : <RegistryOperator>
// // https://www.iana.org/domains/root/db/<ALabel>.html

func (e pslEntry) Comment() string {
parts := []string{
Expand All @@ -145,8 +148,17 @@ func (e pslEntry) Comment() string {
if e.RegistryOperator != "" {
parts = append(parts, []string{":", e.RegistryOperator}...)
}
// parts = append(parts, "\n// https://www.iana.org/domains/root/db/" + e.ALabel + ".html")
return strings.Join(parts, " ")

ianaUrl, err := url.JoinPath(IANA_TLD_URL_BASE, e.ALabel+".html")
if err != nil {
panic(fmt.Sprintf("invalid joined IANA TLD URL for %q: %v", e.ALabel, err))
}
ianaUrl = "// " + ianaUrl

return strings.Join([]string{
strings.Join(parts, " "),
ianaUrl,
}, "\n")
}

// gTLDDatSpan represents the span between the PSL_GTLD_SECTION_HEADER and
Expand Down
11 changes: 8 additions & 3 deletions tools/newgtlds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,22 @@ func TestEntryComment(t *testing.T) {
ALabel: "cpu",
RegistryOperator: "@cpu's bargain gTLD emporium",
},
expected: "// cpu : @cpu's bargain gTLD emporium",
expected: "// cpu : @cpu's bargain gTLD emporium\n// https://www.iana.org/domains/root/db/cpu.html",
},
{
name: "Entry without operator",
entry: pslEntry{
ALabel: "cpu",
},
expected: "// cpu",
expected: "// cpu\n// https://www.iana.org/domains/root/db/cpu.html",
},
{
name: "Entry with non-empty operator",
entry: pslEntry{
ALabel: "cpu",
RegistryOperator: "@cpu's bargain gTLD emporium",
},
expected: "// cpu : @cpu's bargain gTLD emporium",
expected: "// cpu : @cpu's bargain gTLD emporium\n// https://www.iana.org/domains/root/db/cpu.html",
},
}

Expand Down Expand Up @@ -296,9 +296,11 @@ func TestRenderData(t *testing.T) {
}

expectedList := `// ceepeeyou : @cpu's bargain gTLD emporium
// https://www.iana.org/domains/root/db/ceepeeyou.html
ceepeeyou
// cpu
// https://www.iana.org/domains/root/db/cpu.html
cpu
`
Expand Down Expand Up @@ -658,6 +660,7 @@ func TestProcess(t *testing.T) {
// List of new gTLDs imported from https://www.icann.org/resources/registries/gtlds/v2/gtlds.json on 2021-02-07T13:25:56-05:00
// This list is auto-generated, don't edit it manually.
// aaa : American Automobile Association, Inc.
// https://www.iana.org/domains/root/db/aaa.html
aaa
Expand Down Expand Up @@ -711,9 +714,11 @@ aaa
// List of new gTLDs imported from https://www.icann.org/resources/registries/gtlds/v2/gtlds.json on 2021-02-10T00:24:14Z
// This list is auto-generated, don't edit it manually.
// aaa : American Automobile Association, Inc.
// https://www.iana.org/domains/root/db/aaa.html
aaa
// accountants : Binky Moon, LLC
// https://www.iana.org/domains/root/db/accountants.html
accountants
Expand Down

0 comments on commit c0a861f

Please sign in to comment.