Bug 4372 - JavaScript document.write page form does not submit in Safari
Summary: JavaScript document.write page form does not submit in Safari
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Nobody
URL:
Keywords: HasReduction, InRadar
Depends on:
Blocks:
 
Reported: 2005-08-10 11:23 PDT by Vicki Murley
Modified: 2006-10-01 01:41 PDT (History)
4 users (show)

See Also:


Attachments
test case (279 bytes, text/html)
2005-08-10 11:23 PDT, Vicki Murley
no flags Details
patch, without tests or ChangeLog (531 bytes, patch)
2006-09-03 10:37 PDT, Alexey Proskuryakov
mjs: review-
Details | Formatted Diff | Diff
proposed fix (3.60 KB, patch)
2006-09-23 20:34 PDT, Alexey Proskuryakov
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vicki Murley 2005-08-10 11:23:04 PDT
This bug is also in Radar as <rdar://4196379>

Summary: 
 
Submitting an html form of a page that was written with a JavaScript document.write method does not 
work in Safari.  We are concerned about this problem because we are using an encryption/decryption 
product that has the ability to decrypt a page and uses a document.write method to display the page. 
 
Steps to Reproduce:
 
I have created a small page that demonstrates the problem.  On load of the page it will use a 
document.write method to over write the current page with a page that has a form on it.  Upon clicking 
on the submit button Safari does not submit the form; however Internet Explorer 6(WinXP) and Firefox
(Mac) submits the form correctly. 
 
Example page writeform.html:
<html>
<head>
<script>
function writePage() {
   document.write("<html><head></head><body>" +
    "<form name='aform' action='servlet.html' method='post'>" +
    "<input type=submit></form>" +
    "</body></html>");
}
</script>
</head>
<body onload="writePage()">
</body>
</html>
 
Expected Results: 
Safari would submit the form when clicking on the submit button. 
 
Actual Results: 
Safari does not submit the form and stays on current page. 
 
Regression: 
 
This problem occurred on the following platforms:
Mac os X 10.3.9
Safari 1.3(v312) 
PowerBook G4 15-inch A1095. 
 
Mac os X 10.4.2
Safari 2.0(412.3)
PowerBook G4 15-inch A1095. 

-------------------------------------------
Comment 1 Vicki Murley 2005-08-10 11:23:50 PDT
Created attachment 3313 [details]
test case
Comment 2 Eric Seidel (no email) 2005-12-27 15:00:00 PST
Odd.  When I hit the back button (after having hit submit), it tries to take me to /servlet.html
Comment 3 Alexey Proskuryakov 2006-09-03 10:37:50 PDT
Created attachment 10379 [details]
patch, without tests or ChangeLog

All layout tests pass, but it might be just because the reason for the removed check isn't covered... So, I'm asking about validity of such approach.

A workaround is to call document.close() after writing.
Comment 4 Darin Adler 2006-09-03 12:11:19 PDT
Comment on attachment 10379 [details]
patch, without tests or ChangeLog

Oof!

We *definitely* need tests for this one. I can't tell just from code inspection if this is OK or not. I'm not sure what to do about reviewing.
Comment 5 Alexey Proskuryakov 2006-09-14 08:38:35 PDT
The code in question appeared in WebCore in r1035:

	* src/kdelibs/khtml/khtml_part.cpp: Added. Not used yet, but maybe we'll use
	part of it some time soon.

In the KDE repository, the condition has been tweaked many times, but the part I'm removing was introduced in r64718 six years ago:

"applying stripped down version of my anti-tokenizer-crash-on-submit patch
discussed on kfm-devel. It only prevents the crash. A complete solution
for the form data has still to be found."

http://websvn.kde.org/trunk/kdelibs/khtml/khtml_part.cpp?rev=64718&r1=64461&r2=64718

I couldn't find the mentioned kfm-devel discussion.
Comment 6 Maciej Stachowiak 2006-09-23 01:18:00 PDT
I think the approach is right but this needs a layout test.
Comment 7 Alexey Proskuryakov 2006-09-23 20:34:50 PDT
Created attachment 10730 [details]
proposed fix
Comment 8 mitz 2006-09-27 14:42:30 PDT
(In reply to comment #5)
> I couldn't find the mentioned kfm-devel discussion.

http://lists.kde.org/?l=kfm-devel&m=96644872718833&w=2
Comment 9 Darin Adler 2006-09-28 09:09:22 PDT
Comment on attachment 10730 [details]
proposed fix

r=me
Comment 10 Alexey Proskuryakov 2006-10-01 01:41:09 PDT
Committed revision 16694. The fun begins!