Which characters make a URL invalid?

后端 未结 10 1245
小蘑菇
小蘑菇 2020-11-21 05:03

Which characters make a URL invalid?

Are these valid URLs?

  • example.com/file[/].html
  • http://example.com/file[/].html<
10条回答
  •  名媛妹妹
    2020-11-21 05:43

    I need to select character to split urls in string, so I decided to create list of characters which could not be found in URL by myself:

    >>> allowed = "-_.~!*'();:@&=+$,/?%#[]?@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
    >>> from string import printable
    >>> ''.join(set(printable).difference(set(allowed)))
    '`" <\x0b\n\r\x0c\\\t{^}|>'
    

    So, the possible choices are the newline, tab, space, backslash and "<>{}^|. I guess I'll go with the space or newline. :)

提交回复
热议问题