From c9d634499bca2594dbc58011736f8ca041add3c5 Mon Sep 17 00:00:00 2001 From: sloum Date: Mon, 25 May 2020 09:49:34 -0700 Subject: [PATCH 1/9] Alternative way of rendering when bookmarks are not open --- client.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/client.go b/client.go index 80210e6..46531db 100644 --- a/client.go +++ b/client.go @@ -121,15 +121,11 @@ func (c *client) Draw() { } else { for i := 0; i < c.Height-3; i++ { if i < len(pageContent) { - extra := 0 - escapes := re.FindAllString(pageContent[i], -1) - for _, esc := range escapes { - extra += len(esc) - } - screen.WriteString(fmt.Sprintf("%-*.*s", c.Width+extra, c.Width+extra, pageContent[i])) + screen.WriteString(pageContent[i]) + screen.WriteString("\033[0K") screen.WriteString("\n") } else { - screen.WriteString(fmt.Sprintf("%-*.*s", c.Width, c.Width, " ")) + screen.WriteString("\033[0K") screen.WriteString("\n") } } From f47f6597f4931ad178516a1af96c45f3f6abacab Mon Sep 17 00:00:00 2001 From: sloum Date: Mon, 25 May 2020 19:12:52 -0700 Subject: [PATCH 2/9] Adds in the correct variable when checking for existing querystring value --- client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 80210e6..c2b181d 100644 --- a/client.go +++ b/client.go @@ -700,14 +700,14 @@ func (c *client) search(query, uri, question string) { var rootUrl string switch u.Scheme { case "gopher": - if ind := strings.Index(entry, "\t"); ind >= 0 { + if ind := strings.Index(u.Full, "\t"); ind >= 0 { rootUrl = u.Full[:ind] } else { rootUrl = u.Full } c.Visit(fmt.Sprintf("%s\t%s", rootUrl, entry)) case "gemini": - if ind := strings.Index(entry, "?"); ind >= 0 { + if ind := strings.Index(u.Full, "?"); ind >= 0 { rootUrl = u.Full[:ind] } else { rootUrl = u.Full From 022752348747291ae9bc1d15010c6810764482bd Mon Sep 17 00:00:00 2001 From: sloum Date: Mon, 25 May 2020 19:43:19 -0700 Subject: [PATCH 3/9] Adds query escaping --- client.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index c2b181d..4617b2d 100644 --- a/client.go +++ b/client.go @@ -3,6 +3,7 @@ package main import ( "fmt" "io/ioutil" + "net/url" "os" "path/filepath" "regexp" @@ -712,8 +713,8 @@ func (c *client) search(query, uri, question string) { } else { rootUrl = u.Full } - // escapedEntry := url.QueryEscape(entry) // TODO confirm expected behavior re: escaping - c.Visit(fmt.Sprintf("%s?%s", rootUrl, entry)) + escapedEntry := url.PathEscape(entry) + c.Visit(fmt.Sprintf("%s?%s", rootUrl, escapedEntry)) case "http", "https": c.Visit(u.Full) default: From cba3682c27bd0a22f328c35c3a08c0deebcd2c93 Mon Sep 17 00:00:00 2001 From: sloum Date: Tue, 26 May 2020 15:10:12 -0700 Subject: [PATCH 4/9] Adds up one dir relative linking fix --- gemini/gemini.go | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/gemini/gemini.go b/gemini/gemini.go index 98cf059..e97e487 100644 --- a/gemini/gemini.go +++ b/gemini/gemini.go @@ -417,25 +417,33 @@ func parseGemini(b, rootUrl, currentUrl string) (string, []string) { return strings.Join(splitContent[:outputIndex], "\n"), links } +// handleRelativeUrl provides link completion +// takes: +// - u : the relative link as written on the page +// - root : the root url for the site +// - current : the current url a user is on func handleRelativeUrl(u, root, current string) string { if len(u) < 1 { return u } - currentIsDir := (current[len(current)-1] == '/') + currentIsDir := strings.HasSuffix(current, "/") if u[0] == '/' { + // Handle relative off of root return fmt.Sprintf("%s%s", root, u) } else if strings.HasPrefix(u, "../") { + // Handle up one dir currentDir := strings.LastIndex(current, "/") - if currentIsDir { - upOne := strings.LastIndex(current[:currentDir], "/") - dirRoot := current[:upOne] - return dirRoot + u[2:] + upOne := strings.LastIndex(current[:currentDir], "/") + dirRoot := current[:upOne] + if upOne < len(root) { + return fmt.Sprintf("%s%s", root, u[2:]) } - return current[:currentDir] + u[2:] + return dirRoot + u[2:] } if strings.HasPrefix(u, "./") { + // Handle explicit same dir if len(u) == 2 { return current } @@ -443,16 +451,15 @@ func handleRelativeUrl(u, root, current string) string { } if currentIsDir { - indPrevDir := strings.LastIndex(current[:len(current)-1], "/") - if indPrevDir < 9 { - return current + u - } - return current[:indPrevDir+1] + u + // Handle non-prefixed relative link when current URL is a directory + ind := strings.LastIndex(current, "/") + current = current[:ind+1] + return current + u } - ind := strings.LastIndex(current, "/") - current = current[:ind+1] - return current + u + // Handle non-prefixed relative link when current URL is a file + indPrevDir := strings.LastIndex(current, "/") + return current[:indPrevDir+1] + u } func hashCert(cert []byte) string { From c175b45cb9a0cdab657c138be54e08d9bb81ba3d Mon Sep 17 00:00:00 2001 From: sloum Date: Tue, 26 May 2020 21:46:17 -0700 Subject: [PATCH 5/9] Switches relative URLs to RelativeReference lib method --- gemini/gemini.go | 56 +++++++++++------------------------------------- 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/gemini/gemini.go b/gemini/gemini.go index e97e487..44c8545 100644 --- a/gemini/gemini.go +++ b/gemini/gemini.go @@ -6,6 +6,7 @@ import ( "crypto/tls" "fmt" "io/ioutil" + "net/url" "strconv" "strings" "time" @@ -343,8 +344,7 @@ func Visit(host, port, resource string, td *TofuDigest) (Capsule, error) { resource = "/" } currentUrl := fmt.Sprintf("gemini://%s:%s%s", host, port, resource) - rootUrl := fmt.Sprintf("gemini://%s:%s", host, port) - capsule.Content, capsule.Links = parseGemini(body, rootUrl, currentUrl) + capsule.Content, capsule.Links = parseGemini(body, currentUrl) } else { capsule.Content = body } @@ -365,7 +365,7 @@ func Visit(host, port, resource string, td *TofuDigest) (Capsule, error) { } } -func parseGemini(b, rootUrl, currentUrl string) (string, []string) { +func parseGemini(b, currentUrl string) (string, []string) { splitContent := strings.Split(b, "\n") links := make([]string, 0, 10) @@ -399,7 +399,7 @@ func parseGemini(b, rootUrl, currentUrl string) (string, []string) { } if strings.Index(link, "://") < 0 { - link = handleRelativeUrl(link, rootUrl, currentUrl) + link, _ = handleRelativeUrl(link, currentUrl) } links = append(links, link) @@ -418,48 +418,16 @@ func parseGemini(b, rootUrl, currentUrl string) (string, []string) { } // handleRelativeUrl provides link completion -// takes: -// - u : the relative link as written on the page -// - root : the root url for the site -// - current : the current url a user is on -func handleRelativeUrl(u, root, current string) string { - if len(u) < 1 { - return u +func handleRelativeUrl(relLink, current string) (string, error) { + base, err := url.Parse(current) + if err != nil { + return relLink, err } - currentIsDir := strings.HasSuffix(current, "/") - - if u[0] == '/' { - // Handle relative off of root - return fmt.Sprintf("%s%s", root, u) - } else if strings.HasPrefix(u, "../") { - // Handle up one dir - currentDir := strings.LastIndex(current, "/") - upOne := strings.LastIndex(current[:currentDir], "/") - dirRoot := current[:upOne] - if upOne < len(root) { - return fmt.Sprintf("%s%s", root, u[2:]) - } - return dirRoot + u[2:] + rel, err := url.Parse(relLink) + if err != nil { + return relLink, err } - - if strings.HasPrefix(u, "./") { - // Handle explicit same dir - if len(u) == 2 { - return current - } - u = u[2:] - } - - if currentIsDir { - // Handle non-prefixed relative link when current URL is a directory - ind := strings.LastIndex(current, "/") - current = current[:ind+1] - return current + u - } - - // Handle non-prefixed relative link when current URL is a file - indPrevDir := strings.LastIndex(current, "/") - return current[:indPrevDir+1] + u + return base.ResolveReference(rel).String(), nil } func hashCert(cert []byte) string { From 15d67ef23065b5705a64e08005c2e2f9becf0927 Mon Sep 17 00:00:00 2001 From: sloum Date: Wed, 27 May 2020 22:29:41 -0700 Subject: [PATCH 6/9] Adds a make target for release and updates clean to clean it up --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index 5759793..b9ef090 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,7 @@ install-bin: build clean: ${GOCMD} clean rm -f ./bombadillo.1.gz 2> /dev/null + rm -f ./${BINARY}_* 2> /dev/null .PHONY: uninstall uninstall: clean @@ -66,6 +67,13 @@ uninstall: clean rm -f ${DESTDIR}${DATAROOTDIR}/pixmaps/bombadillo-icon.png -update-desktop-database 2> /dev/null +.PHONY: release +release: + GOOS=linux GOARCH=amd64 ${GOCMD} build ${LDFLAGS} -o ${BINARY}_linux_64 + GOOS=linux GOARCH=arm ${GOCMD} build ${LDFLAGS} -o ${BINARY}_linux_arm + GOOS=linux GOARCH=386 ${GOCMD} build ${LDFLAGS} -o ${BINARY}_linux_32 + GOOS=darwin GOARCH=amd64 ${GOCMD} build ${LDFLAGS} -o ${BINARY}_darwin_64 + .PHONY: test test: clean build From 733893edc0fae272925e56008fa81a546cc943e2 Mon Sep 17 00:00:00 2001 From: sloum Date: Wed, 27 May 2020 22:31:23 -0700 Subject: [PATCH 7/9] Adds prerequisit to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1b1af0f..85e4923 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ These instructions will get a copy of the project up and running on your local m ### Prerequisites You will need to have [Go](https://golang.org/) version >= 1.11. +To use the Makefile you will need a make that is GNU Make compatible (sorry BSD folks) ### Building, Installing, Uninstalling From d7a08268b0cc8a0257470b9679bcffa451b62200 Mon Sep 17 00:00:00 2001 From: sloum Date: Wed, 27 May 2020 22:39:44 -0700 Subject: [PATCH 8/9] Updates version info --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 276cbf9..2bf1c1c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.3.0 +2.3.1 From 573eb0d2303d6d4ab6e4a638b3e7b15a380bb2ac Mon Sep 17 00:00:00 2001 From: sloum Date: Thu, 28 May 2020 22:30:48 -0700 Subject: [PATCH 9/9] Fixes issue in makefile that made it so VERSION file was never referenced --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5759793..e160118 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ test : GOCMD := go1.11.13 BUILD_TIME := ${shell date "+%Y-%m-%dT%H:%M%z"} # If VERSION is empty or not defined use the contents of the VERSION file -VERSION := ${shell git describe --tags 2> /dev/null} +VERSION := ${shell git describe --exact-match 2> /dev/null} ifndef VERSION VERSION := ${shell cat ./VERSION} endif