Skip to content
Snippets Groups Projects
Commit bdc5bcdc authored by catch's avatar catch
Browse files

Issue #3077755 by gabesullice, mmenavas, sokru, Wim Leers: Spec compliance...

Issue #3077755 by gabesullice, mmenavas, sokru, Wim Leers: Spec compliance bug: Links object member names must not use colons
parent ddfcac8d
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -309,7 +309,7 @@ protected function normalizeOmissionsLinks(OmittedData $omissions, $format, arra
// random salt and the link href. This ensures that the key is non-
// deterministic while letting use deduplicate the links by their
// href. The salt is *not* used for any cryptographic reason.
$link_key = 'item:' . static::getLinkHash($link_hash_salt, $error['links']['via']['href']);
$link_key = 'item--' . static::getLinkHash($link_hash_salt, $error['links']['via']['href']);
$omission_links['links'][$link_key] = [
'href' => $error['links']['via']['href'],
'meta' => [
......
......@@ -16,8 +16,8 @@
* than one link for a given key.
*
* When normalizing more than one link in a LinkCollection with the same key, a
* unique and random string is appended to the link's key after a colon (:) to
* differentiate the links.
* unique and random string is appended to the link's key after a double dash
* (--) to differentiate the links.
*
* This may change with a later version of the JSON:API specification.
*
......@@ -72,7 +72,7 @@ public function normalize($object, $format = NULL, array $context = []) {
foreach ($object as $key => $links) {
$is_multiple = count($links) > 1;
foreach ($links as $link) {
$link_key = $is_multiple ? sprintf('%s:%s', $key, $this->hashByHref($link)) : $key;
$link_key = $is_multiple ? sprintf('%s--%s', $key, $this->hashByHref($link)) : $key;
$attributes = $link->getTargetAttributes();
$normalization = array_merge(['href' => $link->getHref()], !empty($attributes) ? ['meta' => $attributes] : []);
$normalized[$link_key] = new CacheableNormalization($link, $normalization);
......
......@@ -190,7 +190,7 @@ public function testRead() {
})));
$link_keys = array_keys($single_output['meta']['omitted']['links']);
$this->assertSame('help', reset($link_keys));
$this->assertRegExp('/^item:[a-zA-Z0-9]{7}$/', next($link_keys));
$this->assertRegExp('/^item--[a-zA-Z0-9]{7}$/', next($link_keys));
$this->nodes[1]->set('status', TRUE);
$this->nodes[1]->save();
// 13. Test filtering when using short syntax.
......
......@@ -594,7 +594,7 @@ protected static function errorsToOmittedObject(array $errors) {
],
];
foreach ($errors as $error) {
$omitted['links']['item:' . substr(Crypt::hashBase64($error['links']['via']['href']), 0, 7)] = [
$omitted['links']['item--' . substr(Crypt::hashBase64($error['links']['via']['href']), 0, 7)] = [
'href' => $error['links']['via']['href'],
'meta' => [
'detail' => $error['detail'],
......@@ -658,7 +658,7 @@ protected static function resetOmittedLinkKeys(array &$omitted) {
$reindexed = [];
$links = array_diff_key($omitted['links'], array_flip(['help']));
foreach (array_values($links) as $index => $link) {
$reindexed['item:' . $index] = $link;
$reindexed['item--' . $index] = $link;
}
$omitted['links'] = ['help' => $help] + $reindexed;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment