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

Ok(404l) returns an actual 404 error code #1614

Open
PawkyPenguin opened this issue Dec 1, 2023 · 0 comments
Open

Ok(404l) returns an actual 404 error code #1614

PawkyPenguin opened this issue Dec 1, 2023 · 0 comments

Comments

@PawkyPenguin
Copy link

PawkyPenguin commented Dec 1, 2023

get ("/test") {
 Ok(404l)
}

Will cause the server to return a 404 error, which leads to very sinister bugs when used with something like Ok(counter), where counter needs to be a Long to ensure it's large enough. Don't ask how I found this bug 😉.

The problem lies in ScalatraBase.scala, because this case will not match when given a Long: https://github.com/scalatra/scalatra/blob/d2e247172af40ad21edd16a6a5aebc29549bcb14/core/src/main/scala/org/scalatra/ScalatraBase.scala#L435C1-L435C1

The loop over the response (line 409) hence unwraps the Ok(404l) and returns a 404l, which then matches 404 even though it shouldn't (in a certain sense, this is a problem in Scala... Why the hell would it implicitly downcast here?).

Maybe it would be best to rethink the loop logic? I'm sure it's there for some reason, so it's probably impossible to throw out the program flow itself, but there are other weird corner cases like this, unfortunately. I'd personally disallow plain status codes entirely, but I understand this is probably a Sinatra convention.

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

1 participant