janet-lang / spork

Various Janet utility modules - the official "Contrib" library.
MIT License
123 stars 35 forks source link

spork/http/middleware asserts incorrectly when number is an argument #182

Closed craftybones closed 6 months ago

craftybones commented 6 months ago

https://github.com/janet-lang/spork/blob/19787cc900bbbcc57189e3817599e6245745b331/spork/http.janet#L344

Shouldn't it be (assert msg (string... instead of (assert x (string... ? Since x is a number, this will always be true.

As expected, this following code fails at the wrong level

(def server (http/server (http/middleware 2000)))

Followed by

curl http://localhost:8000/

Returns

*   Trying [::1]:8000...
* connect to ::1 port 8000 failed: Connection refused
*   Trying 127.0.0.1:8000...
* Connected to localhost (127.0.0.1) port 8000
> GET / HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/8.4.0
> Accept: */*
> 
* Empty reply from server
* Closing connection
curl: (52) Empty reply from server
sogaiu commented 6 months ago

Shouldn't it be (assert msg (string... instead of (assert x (string... ? Since x is a number, this will always be true.

The suggested change seems better than the existing code.

bakpakin commented 6 months ago

Thanks @craftybones