Link to home
Start Free TrialLog in
Avatar of Stefan Lennerbrant
Stefan LennerbrantFlag for Sweden

asked on

Inconsistent parameter charset coding in web page submissions

Does anybody recognize this behaviour?

With the following HTML, I open a new page (the same one) supplying a non-ascii form field parameter with value "Ϩ" (a backword "S", like)
The page itself is marked as "charset=iso-8859-1" so I expect that charset to be used for the request.

With "Form1" the request to the web server contains exactly "Ϩ" (however CGI-quoted: "Field1=%26%231000%3B")
With "Form2" the  request however contains the parameter in UTF-8 format (CGI-quoted: "Field2=%CF%A8")
What would be the cause of this difference?

Do note that in IE11 this behaviour is consistent , but in Chrome (ver 73)  I get the Form2 UTF-8 coding only when the Form2 window does not exist to begin with.
Keeping the opened Form2 window on screen, and then re-submitting from the main page (re-using the already opened Form2 window), then Chrome uses "Ϩ" coding also for Form2.

If I change the meta charset tags to "utf-8", then I (of course) always get UTF-8 coding for both Form1 and Form2.

So... why is UTF-8 used in the request for Form2, even though I state "iso-8859-1" as charset (my http server never specifies a charset in the http headers, so the "meta charset" info is the only one available)
Any ideas?

The file is to be named "test.htm"
<html>
<head>
<meta http-equiv="Content-Type" content="iso-8859-1">
<meta charset="iso-8859-1">
<script>
function submit1()
{
  document.Form1.submit();
}
function submit2()
{
  var win = window.open('', 'submit2win');
  if(!win) {
    alert('Cannot open window');
    return;
  }
  var doc = win.document.open('about://', 'replace');
  if(!doc) {
    alert('Cannot open document');
    return;
  }
  doc.writeln('<'+'html>');                                                                                   
  doc.writeln('<'+'head>');
  doc.writeln('<meta http-equiv="Content-Type" content="iso-8859-1">');
  doc.writeln('<meta charset="iso-8859-1">');
  doc.writeln('<\/head>');
  doc.writeln('<'+'body>');
  doc.writeln('<'+'form name=Form2 action="test.htm">');
  doc.writeln('<input name=Field2 type=hidden value="&#1000;">');
  doc.writeln('<\/form>');
  doc.writeln('<'+'script>document.Form2.submit();<\/script>');
  doc.writeln('</body>');
  doc.writeln('</html>');
  doc.close();
}
</script>
</head>
<body>
The time is:
<script>
  var now = new Date();
  document.writeln(now.getTime());
</script>
<br><br>
<form name=Form1 action="test.htm">
<a href="javascript:submit1();">Submit Form1 in this window with Field1="&#1000;"</a>
<input name=Field1 type=hidden value="&#1000;">
</form>
<a href="javascript:submit2();">Submit Form2 in new window with Field2="&#1000;"</a>
</form>
</body>
</html>

Open in new window

Avatar of Stefan Lennerbrant
Stefan Lennerbrant
Flag of Sweden image

ASKER

Here you may see it in action, by the way:

  http://tolva.se/test/test.htm
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.