Browse Source

Merge pull request #457 from writefreely/intl-domain-support

Support international domain names
pull/460/head
Matt Baer 3 years ago
committed by GitHub
parent
commit
7c32dc1045
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 4 deletions
  1. +4
    -1
      collections.go
  2. +19
    -0
      config/config.go
  3. +22
    -2
      config/funcs.go
  4. +1
    -1
      go.mod

+ 4
- 1
collections.go View File

@@ -33,6 +33,7 @@ import (
"github.com/writefreely/writefreely/author"
"github.com/writefreely/writefreely/config"
"github.com/writefreely/writefreely/page"
"golang.org/x/net/idna"
)

type (
@@ -236,7 +237,9 @@ func (c *Collection) DisplayCanonicalURL() string {
if p == "/" {
p = ""
}
return u.Hostname() + p
d := u.Hostname()
d, _ = idna.ToUnicode(d)
return d + p
}

func (c *Collection) RedirectingCanonicalURL(isRedir bool) string {


+ 19
- 0
config/config.go View File

@@ -12,8 +12,11 @@
package config

import (
"net/url"
"strings"

"github.com/writeas/web-core/log"
"golang.org/x/net/idna"
"gopkg.in/ini.v1"
)

@@ -258,6 +261,22 @@ func Load(fname string) (*Config, error) {
if err != nil {
return nil, err
}

// Do any transformations
u, err := url.Parse(uc.App.Host)
if err != nil {
return nil, err
}
d, err := idna.ToASCII(u.Hostname())
if err != nil {
log.Error("idna.ToASCII for %s: %s", u.Hostname(), err)
return nil, err
}
uc.App.Host = u.Scheme + "://" + d
if u.Port() != "" {
uc.App.Host += ":" + u.Port()
}

return uc, nil
}



+ 22
- 2
config/funcs.go View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2018 A Bunch Tell LLC.
* Copyright © 2018, 2020-2021 A Bunch Tell LLC.
*
* This file is part of WriteFreely.
*
@@ -11,14 +11,34 @@
package config

import (
"github.com/writeas/web-core/log"
"golang.org/x/net/idna"
"net/http"
"net/url"
"strings"
"time"
)

// FriendlyHost returns the app's Host sans any schema
func (ac AppCfg) FriendlyHost() string {
return ac.Host[strings.Index(ac.Host, "://")+len("://"):]
rawHost := ac.Host[strings.Index(ac.Host, "://")+len("://"):]

u, err := url.Parse(ac.Host)
if err != nil {
log.Error("url.Parse failed on %s: %s", ac.Host, err)
return rawHost
}
d, err := idna.ToUnicode(u.Hostname())
if err != nil {
log.Error("idna.ToUnicode failed on %s: %s", ac.Host, err)
return rawHost
}

res := d
if u.Port() != "" {
res += ":" + u.Port()
}
return res
}

func (ac AppCfg) CanCreateBlogs(currentlyUsed uint64) bool {


+ 1
- 1
go.mod View File

@@ -42,7 +42,7 @@ require (
github.com/writeas/web-core v1.3.1-0.20210330164422-95a3a717ed8f
github.com/writefreely/go-nodeinfo v1.2.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/net v0.0.0-20200707034311-ab3426394381
gopkg.in/ini.v1 v1.62.0
)



Loading…
Cancel
Save