eclipse-symphony / symphony

Symphony project
MIT License
27 stars 17 forks source link

Parser logs confusing "invalid char literal" error message when request input is double-wrapped #44

Open Haishi2016 opened 4 months ago

Haishi2016 commented 4 months ago

(reported by @DianeHadley)

HTTP Stage Provider uses unifying property parsing to parse all inputs. This means that all properties are parsed as expressions.

Some input should not be parsed, but rather kept intact as their original strings (ex. headers). One way to prevent parsing is by double-wrapping the input with extra single quotes inside the double quotes

Example of header parsing without double-wrapping:

Header input:

"header.Accept": "application/vnd.github+json", "header.X-GitHub-Api-Version": "2022-11-28" Headers after being parsed:

Accept: application/vnd.githubjson X-Github-Api-Version: 1983 Example of header input with double-wrapping:

"header.Accept": "'application/vnd.github+json'", "header.X-GitHub-Api-Version": "'2022-11-28'" When the headers are double-wrapped, the request succeeds, but the parser logs the following error message: :1:1: invalid char literal

This error message is coming from the text/scanner golang library used by Parser.go. This could indicate improper use of the scanner library.

(@Haishi2016)

Yes, this is indeed an improper use of the scanner library, which is designed to scan tokens under the Go language syntax. We probably want to switch to a different scanner in the future.

iwangjintian commented 3 months ago

@Haishi2016 I am a little bit confused on this issue. Could you give me some more background? I only see parser on WaitExpression: https://github.com/eclipse-symphony/symphony/blob/65ad2d86ce9cacccaf0b5289b81d854bf6ebd055/api/pkg/apis/v1alpha1/providers/stage/http/http.go#L317

Haishi2016 commented 2 months ago

this error is not returned by our code but by the text/scanner. We should use a different parser as the parser is designed to scan go syntax.