Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
If two JSON:API links share the same URL and key, but their metadata differs, the last link overwrites the former link.
Release notes snippet
n/a, this is only a theoretical bug because JSON:API links aren't yet a public API.
Comment | File | Size | Author |
---|---|---|---|
#21 | drupal-jsonapi_link_key_collisions-3175884-20.patch | 5.06 KB | gabesullice |
#21 | interdiff.txt | 2.49 KB | gabesullice |
#14 | drupal-jsonapi_link_key_collisions-3175884-14.patch | 3.58 KB | gabesullice |
#14 | interdiff-6-14.txt | 1.06 KB | gabesullice |
#6 | drupal-jsonapi_link_key_collisions-3175884-6.patch | 3.52 KB | gabesullice |
Comments
Comment #2
gabesulliceRough fix.
Comment #3
larowlanThis looks good, we'll need some tests to go with it however
Comment #4
gabesulliceHere ya go!
Test only patch === interdiff
Comment #5
gabesulliceWhoops, forget a docblock.
Comment #6
gabesulliceBah, that missing docblock also meant that the test only patch didn't work.
Comment #7
gabesulliceComment #10
gabesulliceUnrelated fail, I think
Comment #12
mglamanThis looks good and ensure normalization varies based on link attributes. I just have one nit
If we're running array_values why not build $params as a non-associative array?
Then it's just
implode(';', $params)
Uber nit.
Comment #13
juagarc4 CreditAttribution: juagarc4 commentedIt looks good for me too. I have tested it successfully.
@mglaman I like your proposal about non-associative array but I don't understand why you removed the part where the link attributes are joined => "+ $link->getTargetAttributes()". I suppose it's a mistake.
Although I like to maintain things as simple as possible an I like your proposal about non-associative array, I think in this case make sense to use an associative array.
With a non-associative array you can introduce duplicates in $params array provided by $link->getTargetAttributes(). The use of an associative array will avoid this duplicates.
On the other hand, If the duplicates are not a problem an we want to use a non-associative array, the code would be:
Otherwise we will have a wrong output because sprintf() takes the index as part of the string.
Moreover we need to use different names for $params or we will get duplicated values.
Comment #14
gabesulliceThanks for the reviews! I like the suggestion to get rid of
array_values()
.@juagarc4, I'm not worried about duplicates because
getTargetAttributes
can't return duplicates—it's using an associative array internally. I kept the strings with semi-colons and the parameter names in place because then the generated string matches the standard for link parameters in Link headers. That isn't necessary but it's a nice touch I think :)Comment #15
mglaman💥 Looks great to me. RTBC. I know the
array_values
thing was a nit, but I like to remove extra array structuring and destructing if possible.Comment #16
alexpottCommitted e239d3e and pushed to 9.2.x. Thanks!
Comment #18
Wim LeersNice catch! 🤯
Comment #20
alexpott@catch pointed out that a comment might be useful in to explain what the code is doing. This made me realise that the method docs are no longer correct...
I think this needs updating to be more complete.
Comment #21
gabesullice🙈 good catch!
Taking the liberty to go straight to RTBC since this only adds comments.
Comment #23
alexpottCommitted and pushed 99b763a12a to 9.2.x and 849ca9b597 to 9.1.x. Thanks!
Backported to 9.1.x as this is a straight up bug fix.