Skip to content

Commit

Permalink
Fix # in url rendered to %23
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhiFadlillah committed May 26, 2018
1 parent 65d6ddd commit 1baf921
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
17 changes: 9 additions & 8 deletions cmd/cmd-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
dt "github.com/RadhiFadlillah/shiori/database"
"github.com/RadhiFadlillah/shiori/model"
"github.com/RadhiFadlillah/shiori/readability"
valid "github.com/asaskevich/govalidator"
"github.com/gosuri/uiprogress"
"github.com/spf13/cobra"
)
Expand All @@ -36,8 +37,8 @@ func (h *cmdHandler) addBookmark(cmd *cobra.Command, args []string) {
offline, _ := cmd.Flags().GetBool("offline")

// Make sure URL valid
parsedURL, err := nurl.ParseRequestURI(url)
if err != nil || parsedURL.Host == "" {
parsedURL, err := nurl.Parse(url)
if err != nil || !valid.IsRequestURL(url) {
cError.Println("URL is not valid")
return
}
Expand Down Expand Up @@ -231,8 +232,8 @@ func (h *cmdHandler) updateBookmarks(cmd *cobra.Command, args []string) {
// Check if --url flag is used
if cmd.Flags().Changed("url") {
// Make sure URL is valid
parsedURL, err := nurl.ParseRequestURI(url)
if err != nil || parsedURL.Host == "" {
parsedURL, err := nurl.Parse(url)
if err != nil || !valid.IsRequestURL(url) {
cError.Println("URL is not valid")
return
}
Expand Down Expand Up @@ -299,8 +300,8 @@ func (h *cmdHandler) updateBookmarks(cmd *cobra.Command, args []string) {
}

// Parse URL
parsedURL, err := nurl.ParseRequestURI(book.URL)
if err != nil || parsedURL.Host == "" {
parsedURL, err := nurl.Parse(book.URL)
if err != nil || !valid.IsRequestURL(book.URL) {
return
}

Expand Down Expand Up @@ -616,8 +617,8 @@ func (h *cmdHandler) importBookmarks(cmd *cobra.Command, args []string) {
// Save bookmarks to database
for _, book := range bookmarks {
// Make sure URL valid
parsedURL, err := nurl.ParseRequestURI(book.URL)
if err != nil || parsedURL.Host == "" {
parsedURL, err := nurl.Parse(book.URL)
if err != nil || !valid.IsRequestURL(book.URL) {
cError.Println("URL is not valid")
continue
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/serve/web-handler-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/RadhiFadlillah/shiori/model"
"github.com/RadhiFadlillah/shiori/readability"
valid "github.com/asaskevich/govalidator"
jwt "github.com/dgrijalva/jwt-go"
"github.com/julienschmidt/httprouter"
"golang.org/x/crypto/bcrypt"
Expand Down Expand Up @@ -105,8 +106,8 @@ func (h *webHandler) apiInsertBookmark(w http.ResponseWriter, r *http.Request, p
checkError(err)

// Make sure URL valid
parsedURL, err := nurl.ParseRequestURI(book.URL)
if err != nil || parsedURL.Host == "" {
parsedURL, err := nurl.Parse(book.URL)
if err != nil || !valid.IsRequestURL(book.URL) {
panic(fmt.Errorf("URL is not valid"))
}

Expand Down Expand Up @@ -322,8 +323,8 @@ func (h *webHandler) apiUpdateCache(w http.ResponseWriter, r *http.Request, ps h
defer wg.Done()

// Parse URL
parsedURL, err := nurl.ParseRequestURI(book.URL)
if err != nil || parsedURL.Host == "" {
parsedURL, err := nurl.Parse(book.URL)
if err != nil || !valid.IsRequestURL(book.URL) {
return
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/serve/web-handler-ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (h *webHandler) serveBookmarkCache(w http.ResponseWriter, r *http.Request,
},
"hostname": func(s string) string {
parsed, err := nurl.ParseRequestURI(s)
if err != nil || parsed.Host == "" {
if err != nil || len(parsed.Scheme) == 0 {
return s
}

Expand Down
2 changes: 1 addition & 1 deletion readability/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ func toAbsoluteURI(uri string, base *nurl.URL) string {

// If it is already an absolute URL, return as it is
tempURI, err := nurl.ParseRequestURI(uri)
if err == nil && tempURI.Host != "" {
if err == nil && len(tempURI.Scheme) == 0 {
return uri
}

Expand Down

0 comments on commit 1baf921

Please sign in to comment.