Skip to content
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

Wrong request detection with leading whitespace & non http method #447

Closed
rngtng opened this issue May 9, 2023 · 12 comments
Closed

Wrong request detection with leading whitespace & non http method #447

rngtng opened this issue May 9, 2023 · 12 comments

Comments

@rngtng
Copy link
Contributor

rngtng commented May 9, 2023

Hey hey

I'm quite surprised to find out that leading whitespace in front of the http method is supported. Can you elaborate why? IMHO it leads to bad side effects and allow writing (IMHO) rather unreadable code. Like this is a valid syntax:

            GET https://httpbin.org/anything

One bad side effect is that then body is dropped in the following:

POST https://webhook.site/....
Content-Type: text/plain
     Post the following content

And even more surprising, it fails with non http method too. This is rendered as three requests:

POST https://webhook.site/....
PostCode is 1234
Gettogether

My expectation is that lines with leading whitespace are not detected as new requests. Same for lines which have start with HTTP method. wyt?

@rngtng rngtng changed the title Why support leading whitespace for http method Wrong request detection with leading whitespace & non http method May 9, 2023
@AnWeber
Copy link
Owner

AnWeber commented May 9, 2023

I actually don't use whitespaces before the HTTP method either. I would like to check how Intellij behaves here and act accordingly. I think I would adjust the regex here to only accept uppercase letters.

@rngtng
Copy link
Contributor Author

rngtng commented May 9, 2023

Yes. Sounds like a good fix

@AnWeber
Copy link
Owner

AnWeber commented May 10, 2023

So Intellij allows whitespaces, but the request method must be specified with uppercase. I adjust my logic accordingly to avoid false positives. Additionally I add a new switch # @force-separator to force the explicit use of ### to terminate the current region.

@rngtng
Copy link
Contributor Author

rngtng commented May 10, 2023

@AnWeber ok, I see. Thanks for Introducing # @force-separator although it feels a little bit like a hack and not very intuitive. How come PostCode is matched at all? I guess the line in question is this one:
https://github.com/AnWeber/httpyac/blob/main/src/plugins/core/parse/requestHttpRegionParser.ts#L8

I added it here https://regex101.com/r/XwdLRc/1

I'd assume a single space after the method needs to be enforced (to seperate method and url) so what about

... RAPHQL)\s+(?<url>.+?)$
or
... RAPHQL) \s*(?<url>.+?)$

IMHO this would sharpen the parsing and fix my cases?

@rngtng
Copy link
Contributor Author

rngtng commented May 10, 2023

on top, a url can't have whitespaces? so you probably could sharpen the matching here too..

I quick found this reference for allowed URL characters: https://www.freecodecamp.org/news/url-encoded-characters-reference/#:~:text=There%20are%20only%20certain%20characters,that%20can%20have%20special%20meanings.

@AnWeber
Copy link
Owner

AnWeber commented May 10, 2023

@rngtng Unfortunately more difficult. The url can also contain variables that maybe allow whitespace. Now I could check if there is a {{ before the whitespace. But I lose the independence of the parser. And additionally I would limit the extensibility, because there might be use cases for whitespaces without {{ (not encoded query params?).

@AnWeber
Copy link
Owner

AnWeber commented May 10, 2023

I forgot to make the whitespace after the method mandatory. I will add +. It was only missing in http parser :-(

@rngtng
Copy link
Contributor Author

rngtng commented May 10, 2023

Ah right. Forgot about the variables. But imho enforcing a single whitespace would solve it already. With the leading one i can live with.

so imho just add the + and remove the force separator to keep it simple?

@AnWeber
Copy link
Owner

AnWeber commented May 10, 2023

The force separator would just be a workaround in case I run into a problem again. But it would also be solvable by creative variables. I remove it again. The + is already in there. I just forgot to reference the ticket.

AnWeber added a commit that referenced this issue May 10, 2023
@rngtng
Copy link
Contributor Author

rngtng commented May 10, 2023

Perfect. Thanks a lot

@AnWeber
Copy link
Owner

AnWeber commented May 16, 2023

change is released with 6.4.3

@AnWeber AnWeber closed this as completed May 16, 2023
@rngtng
Copy link
Contributor Author

rngtng commented May 16, 2023

thanks a lot!

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