URLの正規形

URL の比較

[1] URL は同じものを表すにも関わらず複数の表現方法がある場合が数多く存在します。 その一方で、 URL (によって表されるもの) が同一かどうか判定したいこともあります。 それ故、2つの URL が同一かどうかを判定する比較演算を定義する必要が生じます。 比較演算の定義に当たっては正規化の方法を規定し、それによる正規形の比較を用いることもあります (もちろん正規化なしで比較を定義することもあります)。 なお、正規化は純粋な比較のため以外にも部品の取り出しやパターン一致のために使われることがありますし、 人間が読むためにも便利です。

[22] URL は表現の自由度が極めて高く、しかも様々な場面で使われているため、 比較正規化の方法は色々定義されています。 比較正規化コストを無視できないというのも様々なバリエーションが生まれる要因となっています。

URL の構文解析、解決、比較と正準化

[15] URL Standard の登場まで、 URL (として解釈される文字列) に対する構文解析解決比較正準化といった各演算の関係は明確に理解されていませんでした。

[18] URL Standard構文解析解決、 基本的な正準化を1つの不可分の演算として改めて正確に定義し、 比較はその結果について (あるいは場合によっては文脈依存の更なる演算を経たものについて) 行うものとしました。

単純文字列比較

URLの単純文字列比較

[23] 最も単純なのが、 URL を単純に文字列として比較する、というものです。

[24] ほとんど自明な比較方法に思えますが、単純比較すら、いくつかバリエーションが考えられます。

[29] 普通は >>25 だろう、と思えるかもしれませんが、規定をよく読むと比較演算への入力が元々の入力そのものではなく解決後の URL だったり、RFC 3986 URI 上の演算として定義されていたりするので注意が必要です。

[30] 普通は仕様上は文字列に対して比較が定義されていますが、現実の実装はしばしばバイト列に対して比較が実装されていたりして、 非ASCII文字が含まれる時に結果が変わってしまうことがあるので、やはり注意が必要です。

[51] 単純な文字列の比較

URL 記録の比較

[45] 次の比較演算は、 URL記録について定義されています。つまり URL構文解析器URL としての基本的な正準化がなされた結果に対して比較するものです。

URL scheme にあまり依存しない比較・正規化

URL scheme に依存した比較・正規化

条件との比較

[13] URLURL との比較ではなく、 URLURL集合との比較が用いられることもあります。 詳しくは URLパターンも参照。

正準化とプロトコル処理

[48] 要求対象の処理では、 absolute-formパスかどうかの判定が必要となる場合があります。

absolute-form 参照。

歴史

[41] RFC 2396 (URI) 6. URI Normalization and Equivalence

In many cases, different URI strings may actually identify the identical resource. For example, the host names used in URL are actually case insensitive, and the URL http://www.XEROX.com is equivalent to http://www.xerox.com. In general, the rules for equivalence and definition of a normal form, if any, are scheme dependent. When a scheme uses elements of the common syntax, it will also use the common syntax equivalence rules, namely that the scheme and hostname are case insensitive and a URL with an explicit ":port", where the port is the default for the scheme, is equivalent to one where the port is elided.

メモ

[10] RFC 4452: info: URI の比較法

[12]

SOAP: 応用依存

[20] Wondering around: Java's URL little secret ( 版) http://www.eishay.com/2008/04/javas-url-little-secret.html

[21] OWL 2 Web Ontology Language Structural Specification and Functional-Style Syntax ( 版) http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#IRIs

[34] RFC 6021 - Common YANG Data Types ( 版) http://tools.ietf.org/html/rfc6021

[37] RFC 6943 - Issues in Identifier Comparison for Security Purposes ( ( 版)) http://tools.ietf.org/html/rfc6943#section-3.3

[38] RDF 1.1 Concepts and Abstract Syntax ( ( 版)) https://dvcs.w3.org/hg/rdf/raw-file/default/rdf-concepts/index.html#dfn-iri-equality

[39] RFC 7252 - The Constrained Application Protocol (CoAP) ( ( 版)) http://tools.ietf.org/html/rfc7252#section-6.3

[42] IRC logs: freenode / #whatwg / 20140903 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20140903#l-914

[43] Web Applications 1.0 r8739 Attempt to mitigate the injection elevation attack on appcache, and describe the attack in detail ( ( 版)) http://html5.org/r/8739

[4] XRDURL scheme 依存の正規化の規則により比較する >>2 としています。

[5] Protocolv2Spec - google-safe-browsing - Client specification for the Google Safe Browsing v2.2 protocol - protect users from malicious web pages - Google Project Hosting ( 版) https://code.google.com/p/google-safe-browsing/wiki/Protocolv2Spec#6.1._Canonicalization

[6] Phishing Protection: Server Spec - MozillaWiki ( 版) https://wiki.mozilla.org/Phishing_Protection:_Server_Spec#Canonical_Hostname_Creation

[9] RFC 7612 - Lightweight Directory Access Protocol (LDAP): Schema for Printer Services ( 版) https://tools.ietf.org/html/rfc7612#section-1.4.2

These URI attributes specify EQUALITY matching with

'caseIgnoreMatch' (rather than with 'caseExactMatch') in order to

conform to the spirit of [STD66], which requires case-insensitive

matching on the host part of a URI versus case-sensitive matching

on the remainder of a URI.

These URI attributes follow existing practice of supporting

case-insensitive equality matching for host names in the

associatedDomain attribute defined in [RFC4524].

[11] Define URL equivalence. Fixes https://www.w3.org/Bugs/Public/show_bug… · whatwg/url@3f0bc8b ( 版) https://github.com/whatwg/url/commit/3f0bc8b84d2f3bdb651207ce0f90c659c3a5a573

[14] Model for Tabular Data and Metadata on the Web ( 版) http://www.w3.org/TR/2015/REC-tabular-data-model-20151217/#h-url-normalization

Metadata Discovery and Compatibility involve comparing URLs. When comparing URLs, processors must use Syntax-Based Normalization as defined in [RFC3968]. Processors must perform Scheme-Based Normalization for HTTP (80) and HTTPS (443) and should perform Scheme-Based Normalization for other well-known schemes.

[44] Sniffly for ports. (mikewest著, ) https://github.com/w3c/webappsec-csp/commit/22d08b990290e49f5a666fad08de16d75bb369e7

[49] はてなブックマークは、登録される URL に独自の正規化を行っているようです。

[50] 例えば、素片識別子空文字列の時、 # ごと除去します。