search: trim trailing whitespace (#184)

When amfora is given a string to search, if that string contains a
valid protocol (gemini://), and that string contains trailing
whitespace, then the string is treated as a search term.

Although perhaps slightly more uncommon, if the input string was as a
result of copy/paste then it's possible the string could contain
trailing spaces, which is not what was intended, but rather should be
removed so that it's treated either as a valid gemini:// link or a
search term.

Some efforts around this appeared in #138
This commit is contained in:
Thomas Adam 2021-02-08 02:52:53 +00:00 committed by GitHub
parent 3111ac0bb0
commit 2f23390696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -198,6 +198,11 @@ func Init(version, commit, builtBy string) {
} else { } else {
// It's a full URL or search term // It's a full URL or search term
// Detect if it's a search or URL // Detect if it's a search or URL
// Remove whitespace from the string.
// We don't want to convert legitimate
// :// links to search terms.
query := strings.TrimSpace(query)
if (strings.Contains(query, " ") && !hasSpaceisURL.MatchString(query)) || if (strings.Contains(query, " ") && !hasSpaceisURL.MatchString(query)) ||
(!strings.HasPrefix(query, "//") && !strings.Contains(query, "://") && (!strings.HasPrefix(query, "//") && !strings.Contains(query, "://") &&
!strings.Contains(query, ".")) && !strings.HasPrefix(query, "about:") { !strings.Contains(query, ".")) && !strings.HasPrefix(query, "about:") {