Skip to content

Illegal query: Invalid input ' ', expected '+', '=', query-char, 'EOI', '&' or pct-encoded #5043

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
jonee opened this issue Jan 9, 2021 · 4 comments

Comments

@jonee
Copy link

jonee commented Jan 9, 2021

Environment details:

  • IBM Cloud Functions
  • Golang or Docker / Native runtime
  • Also reproducible for nodejs

Steps to reproduce the issue:

  1. Create the action with the code below (ibmcloud fn action update helloGo main.go --kind go:1.15 --web true)
  2. Retrieve the web action and invoke with a post
    ibmcloud fn action get helloGo --url <- returns your url

curl -X POST -d '{"name":"sfdsfs4 "}' https://us-south.functions.appdomain.cloud/api/v1/xxx/helloGo.json

Provide the expected results and outputs:

Expects the program to not error out and work as intended

Provide the actual results and outputs:

{"code":"6683a4187e392c69625e2dbafba217ee","error":"Illegal query: Invalid input ' ', expected '+', '=', query-char, 'EOI', '&' or pct-encoded (line 1, column 17): {\"name\":\"sfdsfs4 \"}\n                ^"}

Additional information you deem important:

  • issue happens 100% of the time and should be easy to reproduce
  • It errors out when a post parameter has a space character. If a parameter has the +, it becomes a space.
  • Also, for native / docker it does not reuse variables outside of the main function (as compared to Golang runtime). This is usually used to reuse db connection (separate bug report)

Code for golang runtime
save as main.go
ibmcloud fn action update helloGo main.go --kind go:1.15 --web true
ibmcloud fn action get helloGo --url # returns your url
curl -X POST -d '{"name":"sfdsfs4 "}' https://us-south.functions.appdomain.cloud/api/v1/xxx/helloGo.json
ibmcloud wsk activation logs --last # returns the logs

package main

import (
    "log"
    "os"
    "time"
)
var t0 time.Time

func Main(params map[string]interface{}) map[string]interface{} {
    log.Println("params")
    log.Println(params)

    log.Println("os.Args")
    log.Println(os.Args)

    if t0.IsZero() {
		t0 = time.Now()
		log.Println("new t0")
	} else {
		log.Println("re used t0")
    }

    res := make(map[string]interface{})
    res["body"] = "Hello!"
    return res
}

Code for native / docker runtime
save as main.go
GOOS=linux GOARCH=amd64 go build -o exec
zip exec.zip exec
ibmcloud wsk action update helloGo --native exec.zip
ibmcloud fn action get helloGo --url <- returns your url
curl -X POST -d '{"name":"sfdsfs4 "}' https://us-south.functions.appdomain.cloud/api/v1//helloGo.json
ibmcloud wsk activation logs --last # returns the logs

package main

import (
    "fmt"
    "log"
    "os"
    "time"
    "encoding/json"
)
var t0 time.Time

func main() {
    log.Println("os.Args")
    log.Println(os.Args)

    if t0.IsZero() {
		t0 = time.Now()
		log.Println("new t0")
	} else {
		log.Println("re used t0")
    }

    msg := map[string]string{"body": ("Hello!")}
    res, _ := json.Marshal(msg)
    fmt.Println(string(res))
}
@jonee
Copy link
Author

jonee commented Jan 11, 2021

I can reproduce this for nodejs as well.

Code for nodejs
save as test.js
ibmcloud fn action update helloNode test.js --kind nodejs:10 --web true
ibmcloud fn action get helloNode --url # returns your url
curl -X POST -d '{"name":"sfdsfs4 "}' https://us-south.functions.appdomain.cloud/api/v1/xxx/helloNode

// test.js
'use strict';

async function main(params) {
console.log(params);

return {
body: {payload: Hello world},
statusCode: 200,
headers:{ 'Content-Type': 'application/json'}
};

}

exports.main = main;

@rabbah
Copy link
Member

rabbah commented Jan 13, 2021

I reproduced this against the playground as well code here.

curl -X POST -d '{"name":"sfdsfs4 "}' https://apigcp.nimbella.io/api/v1/web/playground/user463062/z

There is a hidden character after the 4 which is the culprit.

Screen Shot 2021-01-13 at 10 30 37 AM

@rabbah
Copy link
Member

rabbah commented Jan 13, 2021

> curl -X POST -H'content-type: application/json' -d '{"name":"sfdsfs4 "}' https://apigcp.nimbella.io/api/v1/web/playground/user463062/z
Hello!

vs.

> curl -X POST  -d '{"name":"sfdsfs4 "}' https://apigcp.nimbella.io/api/v1/web/playground/user463062/z
{"code":"b8ff36573cb0182382b699c5cf588d6f","error":"Illegal query: Invalid input ' ', expected '+', '=', query-char, 'EOI', '&' or pct-encoded (line 1, column 17): {\"name\":\"sfdsfs4 \"}\n                ^"}

The latter uses Content-Type: application/x-www-form-urlencoded which is effectively a query string. I didn't look up the spec but I suspect you have to encode the character if that was your intent.

@jonee
Copy link
Author

jonee commented Jan 13, 2021

Ok thanks a lot!

it seems I only need to add -H 'content-type: application/json'

@jonee jonee closed this as completed Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants