解析用户名/密码/路径包含特殊字符(如 @、/)的 ftp 网址



通常,ftp url格式为ftp://user[:pass]@ip[:port]/path

但是现在我得到了这个字符串:

ftp://dude:1.1.1.1@1.1.1.1/@1.1.1.1/fml

这似乎是模棱两可的,因为解析结果可以是:

  1. password=1.1.1.1, path=@1.1.1.1/fml
  2. password=1.1.1.1@1.1.1.1/, path=fml

我应该告诉客户这是非法的,还是有更友好的处理方式?谢谢。。

用户名和密码

中的特殊字符

如果远程服务器需要身份验证,则可以在输入 url 字符串中包含用户名和密码。用户名和密码应具有以下特殊字符百分比编码:

] [ ?/<~ # ' ! @ $ % ^ & * ( ) + = } |: " ; ' ,> { 空格

例子:

http://example.com/path/to/input.avi
https://example.com/path/to/input.mov
ftp://example.com/path/to/input.mp3
sftp://example.com/path/to/input.3gp
https://s3.amazonaws.com/bucket-name/input.mpeg
s3://bucket-name/input.mpeg (shorthand for the full HTTP S3 url)
Examples (with username "user" and password "pass!word"):
http://user:pass%21word@example.com/path/to/input.avi
https://user:pass%21word@example.com/path/to/input.mov
ftp://user:pass%21word@example.com/path/to/input.mp3
sftp://user:pass%21word@example.com/path/to/input.3gp
ftp://user:pass%21word@example.com/path/to/input.mp3
Some servers require the username include your domain name (username "user@example.com" and password "pass!word"):
http://user%40example.com:pass%21word@example.com/path/to/input.avi
https://user%40example.com:pass%21word@example.com/path/to/input.mov
ftp://user%40example.com:pass%21word@example.com/path/to/input.mp3
sftp://user%40example.com:pass%21word@example.com/path/to/input.3gp
ftp://user%40example.com:pass%21word@example.com/path/to/input.mp3

最新更新