2011-03-28 Maciej Stachowiak <mjs@apple.com>
authormjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Mar 2011 09:33:59 +0000 (09:33 +0000)
committermjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Mar 2011 09:33:59 +0000 (09:33 +0000)
        Reviewed by Dan Bernstein.

        Assigning location.path to something that doesn't start with / mangles the authority
        https://bugs.webkit.org/show_bug.cgi?id=57209
        <rdar://problem/9195132>

        Tests: http/tests/uri/assign-path-with-leading-slash.html
               http/tests/uri/assign-path-without-leading-slash.html

        * platform/KURL.cpp:
        (WebCore::KURL::setPath): If the new path does not have a leading slash, add one.
2011-03-28  Maciej Stachowiak  <mjs@apple.com>

        Reviewed by Dan Bernstein.

        Assigning location.path to something that doesn't start with / mangles the authority
        https://bugs.webkit.org/show_bug.cgi?id=57209
        <rdar://problem/9195132>

        * http/tests/uri/assign-path-with-leading-slash-expected.txt: Added.
        * http/tests/uri/assign-path-with-leading-slash.html: Added.
        * http/tests/uri/assign-path-without-leading-slash-expected.txt: Added.
        * http/tests/uri/assign-path-without-leading-slash.html: Added.
        * http/tests/uri/resources/assign-path-landing.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@82093 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/uri/assign-path-with-leading-slash-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/uri/assign-path-with-leading-slash.html [new file with mode: 0644]
LayoutTests/http/tests/uri/assign-path-without-leading-slash-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/uri/assign-path-without-leading-slash.html [new file with mode: 0644]
LayoutTests/http/tests/uri/resources/assign-path-landing.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/KURL.cpp

index 344f5c21d02e54d5ad9923d949317298aa19e83e..c683e4ffcb3954fc902487d55d5679032193f831 100644 (file)
@@ -1,3 +1,17 @@
+2011-03-28  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        Assigning location.path to something that doesn't start with / mangles the authority
+        https://bugs.webkit.org/show_bug.cgi?id=57209
+        <rdar://problem/9195132>
+
+        * http/tests/uri/assign-path-with-leading-slash-expected.txt: Added.
+        * http/tests/uri/assign-path-with-leading-slash.html: Added.
+        * http/tests/uri/assign-path-without-leading-slash-expected.txt: Added.
+        * http/tests/uri/assign-path-without-leading-slash.html: Added.
+        * http/tests/uri/resources/assign-path-landing.html: Added.
+
 2011-03-28  Yuta Kitamura  <yutak@chromium.org>
 
         Unreviewed, add Chromium test expectation for fast/text/justify-ideograph-leading-expansion.html.
diff --git a/LayoutTests/http/tests/uri/assign-path-with-leading-slash-expected.txt b/LayoutTests/http/tests/uri/assign-path-with-leading-slash-expected.txt
new file mode 100644 (file)
index 0000000..c07c34c
--- /dev/null
@@ -0,0 +1,3 @@
+The path assignment test redirected successfully. Checking path...
+PASS location.pathname is '/uri/resources/assign-path-landing.html'
+
diff --git a/LayoutTests/http/tests/uri/assign-path-with-leading-slash.html b/LayoutTests/http/tests/uri/assign-path-with-leading-slash.html
new file mode 100644 (file)
index 0000000..ee57beb
--- /dev/null
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<body>
+This test should redirect to a landing page with no doubled slashes in the path.
+
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+</script>
+
+<script>
+location.pathname="/uri/resources/assign-path-landing.html";
+</script>
diff --git a/LayoutTests/http/tests/uri/assign-path-without-leading-slash-expected.txt b/LayoutTests/http/tests/uri/assign-path-without-leading-slash-expected.txt
new file mode 100644 (file)
index 0000000..c07c34c
--- /dev/null
@@ -0,0 +1,3 @@
+The path assignment test redirected successfully. Checking path...
+PASS location.pathname is '/uri/resources/assign-path-landing.html'
+
diff --git a/LayoutTests/http/tests/uri/assign-path-without-leading-slash.html b/LayoutTests/http/tests/uri/assign-path-without-leading-slash.html
new file mode 100644 (file)
index 0000000..4818ced
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<body>
+This test should redirect to a landing page with a success result. If
+it fails to redirect, or redirects to an error page, then there is a bug.
+
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+</script>
+
+<script>
+location.pathname="uri/resources/assign-path-landing.html";
+</script>
diff --git a/LayoutTests/http/tests/uri/resources/assign-path-landing.html b/LayoutTests/http/tests/uri/resources/assign-path-landing.html
new file mode 100644 (file)
index 0000000..caeb38b
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<!DOCTYPE html>
+<html>
+<head>
+  <link rel="stylesheet" href="../../js-test-resources/js-test-style.css">
+  <script src="../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+The path assignment test redirected successfully. Checking path...
+
+<p id="description"></p>
+<div id="console"></div>
+
+
+<script>
+shouldBe("location.pathname", "'/uri/resources/assign-path-landing.html'");
+</script>
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.notifyDone();
+</script>
+
index c7c870a74f5e42e20f8cdd38276ee58e96559df7..80fd0ab737f5148a119154dd9e4c9491f1143630 100644 (file)
@@ -1,3 +1,17 @@
+2011-03-28  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        Assigning location.path to something that doesn't start with / mangles the authority
+        https://bugs.webkit.org/show_bug.cgi?id=57209
+        <rdar://problem/9195132>
+        
+        Tests: http/tests/uri/assign-path-with-leading-slash.html
+               http/tests/uri/assign-path-without-leading-slash.html
+
+        * platform/KURL.cpp:
+        (WebCore::KURL::setPath): If the new path does not have a leading slash, add one.
+
 2011-03-28  Ryosuke Niwa  <rniwa@webkit.org>
 
         Reviewed by Eric Seidel.
index f0d1a24348f9a8e29c68f88b70840045e0f558f3..8c8646e9861c4671dfcb7d48c80bfb1e3010a1d3 100644 (file)
@@ -859,7 +859,11 @@ void KURL::setPath(const String& s)
 
     // FIXME: encodeWithURLEscapeSequences does not correctly escape '#' and '?', so fragment and query parts
     // may be inadvertently affected.
-    parse(m_string.left(m_portEnd) + encodeWithURLEscapeSequences(s) + m_string.substring(m_pathEnd));
+    String path = s;
+    if (path.isEmpty() || path[0] != '/')
+        path = "/" + path;
+
+    parse(m_string.left(m_portEnd) + encodeWithURLEscapeSequences(path) + m_string.substring(m_pathEnd));
 }
 
 String KURL::prettyURL() const