From 9700f559c3e76176e1382ebec67242f277364563 Mon Sep 17 00:00:00 2001 From: "reed@reedloden.com" Date: Wed, 5 Sep 2007 21:29:17 -0700 Subject: [PATCH] Bug 392567 - "Impossible to submit forms to JAR URLs" [p=trev.moz@adblockplus.org (Wladimir Palant) r=bzbarsky sr=sicking a1.9=sicking] --- content/html/content/src/nsFormSubmission.cpp | 47 ++++++------ content/html/content/test/Makefile.in | 1 + content/html/content/test/test_bug392567.html | 72 +++++++++++++++++++ 3 files changed, 100 insertions(+), 20 deletions(-) create mode 100644 content/html/content/test/test_bug392567.html diff --git a/content/html/content/src/nsFormSubmission.cpp b/content/html/content/src/nsFormSubmission.cpp index 559c3ae3bb18..6992401abfcb 100644 --- a/content/html/content/src/nsFormSubmission.cpp +++ b/content/html/content/src/nsFormSubmission.cpp @@ -57,6 +57,7 @@ #include "nsStringStream.h" #include "nsIFormProcessor.h" #include "nsIURI.h" +#include "nsIURL.h" #include "nsNetUtil.h" #include "nsLinebreakConverter.h" #include "nsICharsetConverterManager.h" @@ -532,29 +533,35 @@ nsFSURLEncoded::GetEncodedSubmission(nsIURI* aURI, return NS_OK; } - nsCAutoString path; - rv = aURI->GetPath(path); - NS_ENSURE_SUCCESS(rv, rv); - // Bug 42616: Trim off named anchor and save it to add later - PRInt32 namedAnchorPos = path.FindChar('#'); - nsCAutoString namedAnchor; - if (kNotFound != namedAnchorPos) { - path.Right(namedAnchor, (path.Length() - namedAnchorPos)); - path.Truncate(namedAnchorPos); + nsCOMPtr url = do_QueryInterface(aURI); + if (url) { + url->SetQuery(mQueryString); } + else { + nsCAutoString path; + rv = aURI->GetPath(path); + NS_ENSURE_SUCCESS(rv, rv); + // Bug 42616: Trim off named anchor and save it to add later + PRInt32 namedAnchorPos = path.FindChar('#'); + nsCAutoString namedAnchor; + if (kNotFound != namedAnchorPos) { + path.Right(namedAnchor, (path.Length() - namedAnchorPos)); + path.Truncate(namedAnchorPos); + } - // Chop off old query string (bug 25330, 57333) - // Only do this for GET not POST (bug 41585) - PRInt32 queryStart = path.FindChar('?'); - if (kNotFound != queryStart) { - path.Truncate(queryStart); + // Chop off old query string (bug 25330, 57333) + // Only do this for GET not POST (bug 41585) + PRInt32 queryStart = path.FindChar('?'); + if (kNotFound != queryStart) { + path.Truncate(queryStart); + } + + path.Append('?'); + // Bug 42616: Add named anchor to end after query string + path.Append(mQueryString + namedAnchor); + + aURI->SetPath(path); } - - path.Append('?'); - // Bug 42616: Add named anchor to end after query string - path.Append(mQueryString + namedAnchor); - - aURI->SetPath(path); } return rv; diff --git a/content/html/content/test/Makefile.in b/content/html/content/test/Makefile.in index 6c19dcee9cb0..c98acd1a9433 100644 --- a/content/html/content/test/Makefile.in +++ b/content/html/content/test/Makefile.in @@ -96,6 +96,7 @@ _TEST_FILES = test_bug589.html \ test_bug388746.html \ test_bug389797.html \ test_bug391994.html \ + test_bug392567.html \ test_bug394700.html \ $(NULL) diff --git a/content/html/content/test/test_bug392567.html b/content/html/content/test/test_bug392567.html new file mode 100644 index 000000000000..40876188f553 --- /dev/null +++ b/content/html/content/test/test_bug392567.html @@ -0,0 +1,72 @@ + + + + + Test for Bug 392567 + + + + + +Mozilla Bug 392567 +

+ +
+
+
+ +