Url: "https://www.drupal.org/node/21947" - 200 response. It's ok.
Url: "https://www.drupal.org/node/21947." - 200 response instead of 404
Url: "https://www.drupal.org/user/443578" - 200, ok.
Url: "https://www.drupal.org/user/443578." - 200 response instead of 404
Tested on clear Drupal-7.52 installation without any contrib modules (PostgreSQL-9.3.13 FreeBSD, MySQL-5.5.53 Ubuntu):
"http://example.ru/node/1." - 200 response
"http://example.ru/user/3." - 200 response
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | 2830428-25.patch | 1.48 KB | mcdruid |
| #23 | 2830428-23_test_only.patch | 1 KB | mcdruid |
| #22 | 2830428-22.patch | 464 bytes | mcdruid |
| #16 | Wrong_response_for_non_integer_id_for_node_and_user-2830428-16.patch | 486 bytes | telecjose |
| #13 | Wrong_response_for_non_integer_id_for_node_and_user-2830447-13.patch | 485 bytes | telecjose |
Comments
Comment #2
ansebul commentedComment #3
aditya.n commentedComment #5
Rajender Rajan commentedComment #6
Rajender Rajan commentedComment #8
telecjose commentedComment #9
telecjose commentedComment #11
telecjose commentedComment #13
telecjose commentedComment #14
telecjose commentedComment #15
telecjose commentedThis is fixed and need to be tested by the community. Regards.
Comment #16
telecjose commentedComment #17
ethomas08 commentedWorks v well! Changing status to RTBC.
Comment #18
ethomas08 commentedTested on a clean install of D7
Comment #19
mcdruid commentedIIUC this is down to PHP's helpful type juggling.
(Example using PHP 7.4.3)
Any reason we couldn't change this to a strict comparison
===instead of adding another test with a cast and a function call?What does D8/9 do?
Comment #20
mcdruid commentedLooks like D9 may use the same comparison here:
https://git.drupalcode.org/project/drupal/-/blob/9.4.0-alpha1/core/lib/D...
So does D9 have the same problem?
Comment #21
mcdruid commentedThe IS mentions PostgreSQL as well as MySQL and the comment for \DrupalDefaultEntityController::cleanIds mentions:
Doing a bit of manual testing with MySQL initially I can confirm that e.g. these two URLs both successfully load node 1:
Requesting the node with a different suffix to the id yields a 404 though - e.g.:
I tried this with every non-alphanumeric character between 32-128 in the ASCII range and as far as I can see the dot is the only case where this happens. (Ignoring the characters that have special meanings in URLs such as & # ? etc..)
I believe that's down to the fact that the dot suffix is the only one that counts as numeric, presumably because it's treated as a decimal point even when there's nothing after it.
In D7, after the array_filter which lets '1.' through, the array of ids is mapped to the intval callback so '1.' becomes '1' which is why this works.
In other words, the case of the dot / decimal point after the id in the url seems to be unique.
Do we really want to "fix" this? On the one hand it's not uncommon for URLs to have a dot added accidentally e.g. in emails. However, it's technically probably duplicate content and would also likely be keyed differently by the page cache etc..
Comment #22
mcdruid commentedConfirmed that the same thing does not happen in D9; requesting
node/1.yields a 404 as it should.So I'd say we're okay to fix this as we see fit in D7.
I'd like to test the strict comparison approach (this patch does that), and I'd also suggest that we add a very basic test for this.
Comment #23
mcdruid commentedHere's a test only patch that should fail without an accompanying fix.
I'll have a look at why the previous patch is apparently breaking at least one test.
Comment #25
mcdruid commentedThe test which is breaking with the
$id === (int) $idpatch isFilePrivateTestCase::testPrivateFile.AFAICS that is because the test results in file_load_multiple() being called with an array of fids that just contains a 0.
Looks like that 0 gets passed to the array_filter callback as a string, which is where the strict comparison causes a problem:
...whereas:
So hmm...
I have a feeling passing the 0 as an entity id is a bug in itself, but perhaps we're better off minimising the risk of breaking things here and going with the implementation that doesn't break the existing test suite.
This patch combines #16 with the new test which we'd hope should pass.
Comment #26
mcdruid commentedComment #27
mcdruid commentedComment #28
fabianx commentedOne thing:
Can we have a quick comment of why the ctype_digit is there.
RTBC + 1, approved for Merge! Thanks all!
Comment #29
fabianx commentedComment #31
mcdruid commentedGood suggestion - I've added this comment on commit:
We could add a todo to chase down the 0 as a string problem, but realistically I'm not sure there'd be much point.
Added a CR too as this is a change in behaviour.
Thank you everyone!