Skip to content

form URL encoding fails #4013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
s0170071 opened this issue Dec 21, 2017 · 5 comments
Closed

form URL encoding fails #4013

s0170071 opened this issue Dec 21, 2017 · 5 comments
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.

Comments

@s0170071
Copy link

s0170071 commented Dec 21, 2017

Basic Infos

Hardware

Hardware: Wemos D1 mini
Core Version: 2.3.0 / 2.4.0rc2

Description

the URL encoding for post forms is broken for post forms with the default enctype

Behaviour with core version 2.3.0 method='post' .. OK
Behaviour with core version 2.3.0 method='post'enctype='multipart/form-data'' .. OK
Behaviour with core version 2.4.0rc2 method='post' .. FAIL
Behaviour with core version 2.4.0rc2 method='post'enctype='multipart/form-data'' .. OK

Fail means that you have to URLencode the string in the form yourself in order for it to get received as intended by the ESP. This means that it probably gets URLdecoded although it was not ENcoded in the first place.

Using the test sketch:

  1. fill in ssid and password.
  2. run and open the serial monitor. Open the IP displayed here in the browser.
  3. open a.htm for method='post' form, b.htm for a method='post'enctype='multipart/form-data'' form
  4. write something with a "%" in the field and hit enter. Watch the serial window.

Settings in IDE

Module: Wemos D1 mini
Flash Size: 4MB
CPU Frequency: 80Mhz
Flash Mode: qio
Flash Frequency: 512k
Upload Using: SERIAL
Reset Method: power cycle

Sketch


#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

const char* webpage ="<!DOCTYPE html><html lang='en'><head></head><body><form name='frmselect' method='post'><table><TR><TD colspan='2'><h2>Form Test</h2><TR><TD>Line 1:<TD><input type='text' name='abc' maxlength=64 value='%ip%'><TR><TD><TD><input type='submit' value='Submit'><input type='hidden' name='edit' value='1'><input type='hidden' name='page' value='1'></table></form></body></html>";
const char* webpage2 ="<!DOCTYPE html><html lang='en'><head></head><body><form name='frmselect' method='post'enctype='multipart/form-data'><table><TR><TD colspan='2'><h2>Form Test</h2><TR><TD>Line 1:<TD><input type='text' name='abc' maxlength=64 value='%ip%'><TR><TD><TD><input type='submit' value='Submit'><input type='hidden' name='edit' value='1'><input type='hidden' name='page' value='1'></table></form></body></html>";
const char* ssid = "...";
const char* password = "...";

ESP8266WebServer server(80);

void handlea() {
  server.send(200, "text/html", webpage);
}
void handleb() {
  server.send(200, "text/html", webpage2);
}
 

void setup(void){
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
 

  server.on("/a.htm", handlea);
  server.on("/b.htm", handleb);
  server.begin();
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();
  String message = "";
  Serial.println(">" + server.arg("abc") +"<");
  delay(1000);
}
@kapyaar
Copy link

kapyaar commented Dec 26, 2017

I had a similar issue, and posted this.

#3791

Based on the reply by devyte, I used the Parsing.cpp PR code and that resolved the issue. Can you check that out?

@devyte
Copy link
Collaborator

devyte commented Dec 28, 2017

@s0170071 does PR #3313 fix this?

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Dec 28, 2017
@s0170071
Copy link
Author

s0170071 commented Dec 28, 2017 via email

@devyte
Copy link
Collaborator

devyte commented Dec 28, 2017

@s0170071 I understand it's a bug in how the decoding is done.
Please test with latest git plus the referenced PR.

@s0170071
Copy link
Author

Just confirmed. PR #3313 fixes this, current latest git (head revision) doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

3 participants