According to RFC 3986 Section 3 - Syntax Components:

The scheme and path components are required, though the path may be empty (no characters).

Can someone clarify how the path component can be required if it's able to be empty? Maybe I'm misunderstanding the definition of "required" in this context, but I assumed it to mean something along the lines of "must be non-empty," which obviously conflicts with the spec here.

有帮助吗?

解决方案

Here, "required" means merely "always present": the scheme and path components of an absolute URI are always present.

The scheme component can't be empty because the production "scheme" requires at least one character.

The path component can be empty because the production "path-empty" (part of "hier-part") consists of zero characters.

其他提示

A common practical example of an empty - more precisely, an abempty - path is a URI like http://stackoverflow.com where the path is empty. The authority component (in this case it is stackoverflow.com) alone isn't enough information to identify a resource.

When the authority is empty, the path must begin with a / in order to distinguish the path from the authority - scheme:/// is a valid URI - hence an abempty path. Also take a look at this answer for further reading.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top