[go: nahoru, domu]

Make file:///Y: canonical on all systems

Currently, on Windows only, the canonical form of file:///Y: is
file:///Y:/. However, this causes the operation of taking a
canonical form not being idempotent, because the canonical form of
file:///./Y: is file:///Y:, which itself is not canonical.

After a discussion on https://crbug.com/1078698 and inspecting
https://url.spec.whatwg.org/, it seems like the correct solution is to
actually make file:///Y: canonical (note: this is already the case
everywhere but on Windows).

That solution is implemented in this CL, including adding test cases
for valid-URL examples mentioned in https://crbug.com/1078698#c13.

Bug: 1078698
Change-Id: Ib16f92541b715d2137a0ca21b2c0ec0e0af18db7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2190679
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#767758}
diff --git a/url/url_canon_fileurl.cc b/url/url_canon_fileurl.cc
index 6277289..067ed58 100644
--- a/url/url_canon_fileurl.cc
+++ b/url/url_canon_fileurl.cc
@@ -76,8 +76,8 @@
     Component sub_path = MakeRange(after_drive, path.end());
     Component fake_output_path;
     success = CanonicalizePath(spec, sub_path, output, &fake_output_path);
-  } else {
-    // No input path, canonicalize to a slash.
+  } else if (after_drive == path.begin) {
+    // No input path and no drive spec, canonicalize to a slash.
     output->push_back('/');
   }