bufio.NewReader changes blanks to plus signs

I am running go version go1.12.1 windows/amd64
my laptop is windows 10 64 bit
I have written a GO program to act as a CGI script under my Apache web server

A FORM on my web page submitted a POST method request to the GOlang CGI script program.

To my surprise the blanks in the data field were changed to blanks.

I used bufio.NewReader to read in the standard input containing the POST method data as follows

		reader := bufio.NewReader(os.Stdin)
		for {
			looptext, _ := reader.ReadString('\n')
			count := len(looptext)
			if count == 0 {
			post_data += looptext + "\n"
			post_vars := strings.Split(looptext, "&")
			for _, pvar := range post_vars {
				pair := strings.SplitN(pvar, "=", 2)
				fields_count += 1
				fields_map[pair[0]] = pair[1]
		} // FOR over lines of POST data

Why were the blanks changed to plus signs ? So far Google searching has not found anything

Please show us the headers and the body of the POST request.

Also take a look at https://en.wikipedia.org/wiki/Percent-encoding#The_application/x-www-form-urlencoded_type:

The encoding used by default is based on an early version of the general URI percent-encoding rules,[4] with a number of modifications such as newline normalization and replacing spaces with + instead of %20 .

Thanks for the reply. I have been so used to doing CGI programming in Perl where the Perl CGI library would handle all the decoding for me.

I added a call to url.QueryUnescape() and now the data is exactly as expected. Thanks again.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.