ref: bbda53b143c07207a137b2a8a64d0c42c498a79b
parent: 5a55f1448d2004d6cb54cbd34172ec3b9925715d
author: Julien Blanchard <[email protected]>
date: Thu Dec 10 06:17:09 EST 2020
Use strbeg instead of overconfident strstr
--- a/castor.c
+++ b/castor.c
@@ -160,13 +160,13 @@
char*
protocol(char *link)
{
- if(strstr(link, "http://") != nil){
+ if(strbeg(link, "http://") == 0){
return " [WWW]";
- }else if(strstr(link, "https://") != nil){
+ }else if(strbeg(link, "https://") == 0){
return " [WWW]";
- }else if(strstr(link, "gopher://") != nil){
+ }else if(strbeg(link, "gopher://") == 0){
return " [GOPHER]";
- }else if(strstr(link, "finger://") != nil){
+ }else if(strbeg(link, "finger://") == 0){
return " [FINGER]";
}else{
return "";
@@ -176,13 +176,13 @@
char*
symbol(char *link)
{
- if(strstr(link, "http://") != nil){
+ if(strbeg(link, "http://") == 0){
return "⇄";
- }else if(strstr(link, "https://") != nil){
+ }else if(strbeg(link, "https://") == 0){
return "⇄";
- }else if(strstr(link, "gopher://") != nil){
+ }else if(strbeg(link, "gopher://") == 0){
return "⇒";
- }else if(strstr(link, "finger://") != nil){
+ }else if(strbeg(link, "finger://") == 0){
return "⇒";
}else{
return "→";
@@ -505,7 +505,7 @@
if(strlen(t) == 0)
return;
- if(strstr(t, "gemini://") == NULL)
+ if(strbeg(t, "gemini://") != 0)
t = smprint("gemini://%s", t);
gemini_get(urlparse(nil, t));
@@ -527,7 +527,7 @@
if(link==nil)
return;
- if(strstr(link, "gemini://") != nil || strstr(link, "://") != nil){
+ if(strbeg(link, "gemini://") != 0 || strstr(link, "://") != nil){
next_url = urlparse(nil, link);
}else{
/* assuming relative URL */