Slim icon indicating copy to clipboard operation
Slim copied to clipboard

Query strings unpredictably produce 404s

Open freen opened this issue 13 years ago • 5 comments

Hi,

I started experiencing an issue with an API I develop using Slim, when I installed it in a new environment and loaded a fresh copy of Slim using Composer.

The error is very simple to describe, but I can't understand why it's occuring.

My API includes these three routes:

  • /api/1/auth/session/
  • /api/1/activity/
  • /api/1/messages/rows/ *

All of these URLs produce a 404 (hit slim's app#notFound) when I add a query string (or even a simple question mark) to the end of the URLs, except the third, starred route, for whatever reason:

These produce 404s:

  • /api/1/auth/session/?this=produces&a=404
  • /api/1/activity/?this=too
  • /api/1/activity/?
  • /api/1/auth/session/?

For some reason these don't:

  • /api/1/messages/rows/?this=works&for=some&reason
  • /api/1/messages/rows/?

They're all defined in the same way ($v equals 1):

$app->get("/$v/messages/rows/?", function () use ( /** etc */ ) { /** ... */ });

$app->get("/$v/activity/?", function () use ( /** etc */ ) { /** ... */ });

$app->get("/$v/auth/session/?", function() use ( /** etc */ ) { /** ... */ });

There's no variation when I remove the trailing ? from the route's regular expresion. (The strange 404s continue.)

I ran a git bisect, which identified this commit as being the origin of the bug:

a35767746009ff818e6375b72f23a2cf7de5f1a4 Add HHVM compatibility

$ cd vendor/slim/slim/
$ git bisect start
$ git bisect good b8181de1112a1e2f565b40158b621c34ded38053
$ git bisect bad 3dec4f9ee2e9c204a9f334afd72abc174c1b792e
Bisecting: 77 revisions left to test after this (roughly 6 steps)
[a5094b7672c2b815a9735bd7605c3feaf17c926c] Merge pull request #535 from mnlg/set-replace-container
$ git bisect good
Bisecting: 34 revisions left to test after this (roughly 5 steps)
[f68cbb7d1e0cedd52752e70865480356dc9dc924] Fix merge conflicts
$ git bisect good
Bisecting: 17 revisions left to test after this (roughly 4 steps)
[4803b21b8a52188d1ad3a61c23b595c686e19de7] Bump version numbers
$ git bisect good
Bisecting: 9 revisions left to test after this (roughly 3 steps)
[1817ff97604c99fe6bfd98862b269cab12000482] Fix README typo
$ git bisect bad
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[29ad3bb0588b97af099a07267bfc32cef688ecb5] Remove vagrant files
$ git bisect bad
Bisecting: 1 revision left to test after this (roughly 1 step)
[a35767746009ff818e6375b72f23a2cf7de5f1a4] Add HHVM compatibility
$ git bisect bad
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[2b12c9b076b78bdec1f30c51001ab752d282baf7] Bump version numbers
$ git bisect good
a35767746009ff818e6375b72f23a2cf7de5f1a4 is the first bad commit
commit a35767746009ff818e6375b72f23a2cf7de5f1a4
Author: = <[email protected]>
Date:   Sun Sep 29 16:06:05 2013 -0400

    Add HHVM compatibility

:040000 040000 221b98dd56ffd7930ab2060524c8d6a84329dec1 c5daabf0acf6f8521d1a3b24a4cb27e9a8e0d4a5 M  Slim
:040000 040000 46d33b2bc806153baab4de712cbe31ede1767c93 0429b5290ad4202d6027a6faa1aee07034b619c6 M  tests

Anyone got any ideas as to what could be producing this behavior? I think it's a bug!

freen avatar Nov 22 '13 21:11 freen

I'm inclined to believe this is By Design.

frnco avatar Nov 22 '13 22:11 frnco

I can't imagine why Slim routes would enforce that no query strings exist, or why it would throw 404s when they're present in the URL.

Or, even if this was enforced, why it would happen for some routes, but not others, where there is no apparent difference between their definition.

As far as I can tell, my route's regular expressions are properly formed. I'm only matching against the beginning of the URL, so the query string shouldn't be affecting the behavior in my opinion.

freen avatar Nov 22 '13 22:11 freen

@freen Can you push a sample app to pastebin that I can run locally to duplicate? Also, can you confirm you are running version 2.3.5?

codeguy avatar Nov 22 '13 22:11 codeguy

Not sure what the version is, only the checksums.

The sample app isolated the problem to the .htaccess :) See below.

Thanks for listening!

http://pastebin.com/zXHZhdCZ

freen avatar Nov 22 '13 22:11 freen

Glad you got it resolved!

codeguy avatar Nov 23 '13 00:11 codeguy