paritytech / substrate

Substrate: The platform for blockchain innovators
Apache License 2.0
8.39k stars 2.65k forks source link

wrong name regex to filter url when provide `--name=www` as parameter in cli #14574

Closed atenjin closed 1 year ago

atenjin commented 1 year ago

Is there an existing issue?

Experiencing problems? Have you tried our Stack Exchange first?

Description of bug

when using --name parameter and the value contains word www, the regex in the code will think this is a url and return error and exit. However we should allow user to use the word www for it's a normal word.

The reason is the wrong regex in function:

https://github.com/paritytech/substrate/blob/c446786a498dee7b413de101efc3c339d3eddf44/client/cli/src/commands/run_cmd.rs#L395-L414

In L407

    let invalid_patterns = r"(https?:\\/+)?(www)+";

The \ in this part should be /\ to let regex can recognize it.

Thus, it at least should be (refer to linker https://uibakery.io/regex-library/url):

    let invalid_patterns = r"^https?:\/\/";

For the preview regex has filtered the char ., so we just need to find out the schema part.

Steps to reproduce

example:

# just www
./target/release/substrate --tmp --dev --name=www
Error: Input("Invalid node name 'www'. Reason: Node name should not contain urls. If unsure, use none.")
# contains www
./target/release/substrate --tmp --dev --name=aawww
Error: Input("Invalid node name 'aawww'. Reason: Node name should not contain urls. If unsure, use none.")

./target/release/substrate --tmp --dev --name=wwwaa
Error: Input("Invalid node name 'wwwaa'. Reason: Node name should not contain urls. If unsure, use none.")