【问题标题】:Characters a URL can't end with?URL不能以字符结尾?
【发布时间】:2018-10-23 04:23:28
【问题描述】:

网络浏览器 URL (http/https)不能以哪些字符(如果有)结尾?

据我所知,没有使用控制字符,例如

  • \0 无。
  • \t 标签。
  • \n换行。
  • 空间(从测试看来,这已被剥离)。

是否有此类字符的完整列表?

【问题讨论】:

    标签: url input-sanitization


    【解决方案1】:

    URI 可以如何结束的三种情况:

    • 带有路径组件(如果它没有查询/片段)

        http://example.com/
        http://example.com/path
        http://example.com/path/path
      
    • 带有查询组件(如果它没有片段)

        http://example.com/?query
        http://example.com/path?query
        http://example.com/path/path?query
      
    • 带有片段组件

        http://example.com/#fragment
        http://example.com/path#fragment
        http://example.com/path/path#fragment
        http://example.com/?query#fragment
        http://example.com/path?query#fragment
        http://example.com/path/path?query#fragment
      

    URI standard 对这三个组件(PathQueryFragment)的末尾没有任何限制,因此允许相同的字符出现在组件的其他任何位置:

    空间(从测试看来这是被剥离的)

    URI 可以在末尾有(多个)空格字符(在所有三种情况下),但它们必须是百分比编码的。无论在哪里,都不允许未编码的空格。

    http://example.com/path-ending-with-four-spaces-%20%20%20%20
    

    如果用户代理尝试将用户输入转换为有效的 URI(即,对所有不能出现在组件中的字符进行百分比编码),它可能会假设尾随空格不打算成为 URI 的一部分,然后剥离它们。

    制表符和换行符也是如此。如果使用百分比编码,它们可以是 URI 的一部分。

    【讨论】:

      猜你喜欢
      • 2015-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-27
      • 2019-01-26
      • 2020-11-11
      • 1970-01-01
      相关资源
      最近更新 更多