stacks-cli icon indicating copy to clipboard operation
stacks-cli copied to clipboard

Handle missing scheme

Open ppvg opened this issue 7 years ago โ€ข 5 comments

Entering a URL without a scheme causes the process to exit silently:

$ stacks-cli
? Which website stack do you wanna browse ? (e.g. https://github.com) github.com
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ ๐Ÿท  type โ”‚ ๐Ÿ‘€  name โ”‚ ๐Ÿ’ช  confidence โ”‚ โ“  categories โ”‚ ๐Ÿ’ป  website โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
$ echo $?
0

Would it be reasonable to assume https:// or https:// if the entered URL lacks a scheme?

ppvg avatar Nov 29 '17 07:11 ppvg

This should be fixed here https://github.com/WeiChiaChang/stacks-cli/pull/25/files#diff-22d5d2b57c69d2e1ac054c4d0f744ff1R87 ๐Ÿ‘

o3LL avatar Nov 29 '17 10:11 o3LL

That fixes the silent exit. ๐Ÿ‘

It would be great if it would also specifically handle the missing scheme in a more friendly way, for example by defaulting to https:///http:// or with a helpful error message.

ppvg avatar Nov 29 '17 10:11 ppvg

Yes, using https://github.com/epoberezkin/ajv#formats !

o3LL avatar Nov 29 '17 10:11 o3LL

Why use an entire validation library?

if(inputstr.indexOf("http://") < 0 && inputstr.indexOf("https://") < 0){
    console.log("No scheme found, defaulting to http");
    inputstr = "http://" + inputstr;
}

That's all you need.

dospunk avatar Nov 30 '17 22:11 dospunk

Send a PR @dospunk !

o3LL avatar Nov 30 '17 22:11 o3LL