4

ファイル/ディレクトリ パスを処理する適切な方法は を使用することPath.AltDirectorySeparatorCharですが、これは html ソース パスに適用されますか?

または、バックスラッシュが html に必要なパス区切り文字であるということですか? 私はいつもバックスラッシュ (つまり<img src="images\birthdaysurprise.jpg" />) を使用してそれを行ってきましたが、今までずっと不適切に行っていたのではないかと思っています。

4

2 に答える 2

2

法律の正確な文言はわかりませんが、すべてのパス区切り記号にはスラッシュを使用してください。Windows でさえ、その API で区切り記号としてスラッシュを使用できます。

Windows プラットフォームではバックスラッシュを使用できますが、次の点に注意してください。

  • 奇妙に見える
  • *nix ベースのシステムに移行すると、死んでギャグになります。
  • スラッシュを前提とする一部のコードが壊れる可能性があります
  • \多くの場合、エスケープ シーケンスを開始するため\n、予期しない方法で変換される可能性があります。
于 2012-09-05T17:27:00.510 に答える
1

「法律の文言」は、スラッシュ ('/') がそれを行う方法であるということです。RFC 2396、Uniform Resource Identifiers (URI): Generic Syntax 、 §3 、「URI 構文コンポーネント」:

The URI syntax does not require that the scheme-specific-part have
any general structure or set of semantics which is common among all
URI.  However, a subset of URI do share a common syntax for
representing hierarchical relationships within the namespace.  This
"generic URI" syntax consists of a sequence of four main components:

   <scheme>://<authority><path>?<query>

each of which, except <scheme>, may be absent from a particular URI.
For example, some URI schemes do not allow an <authority> component,
and others do not use a <query> component.

   absoluteURI   = scheme ":" ( hier_part | opaque_part )

URI that are hierarchical in nature use the slash "/" character for
separating hierarchical components.  For some file systems, a "/"
character (used to denote the hierarchical structure of a URI) is the
delimiter used to construct a file name hierarchy, and thus the URI
path will look similar to a file pathname.  This does NOT imply that
the resource is a file or that the URI maps to an actual filesystem
pathname.

   hier_part     = ( net_path | abs_path ) [ "?" query ]

   net_path      = "//" authority [ abs_path ]

   abs_path      = "/"  path_segments

URI that do not make use of the slash "/" character for separating
hierarchical components are considered opaque by the generic URI
parser.

   opaque_part   = uric_no_slash *uric

   uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
                   "&" | "=" | "+" | "$" | ","

We use the term <path> to refer to both the <abs_path> and
<opaque_part> constructs, since they are mutually exclusive for any
given URI and can be parsed as a single component.

スキーム機関を区別するために、URI には最小限の数のスラッシュが必要です。URI の残りの部分 (パスクエリコンポーネント) は、関連するスキーム機関のコンテキスト内でのみ意味を持ちます。ただし、考慮すべき点がいくつかあります。

  • 1 つ目は、URIパスはファイルシステム パスではありません(URI スキームがfile(でない限り) です。URI パスは、特定のファイル システム エントリにマップされる(またはマップされない)権限file://...意味する単なる識別子です。

  • 2 つの不透明な URI パス ('/'パス区切りとして使用されていないパスは、一般的なツールではうまく処理できません。さらに、問題のパスが不透明であることが必ずしも明らかではありません。つまり、不透明な URI に一般的なツールを適用すると、予想外の行動に。

于 2012-09-05T18:06:53.820 に答える