The JSON API Spec does not explicitly define the structure of URL in a Link (either when the link value is a URL string or when the link value is an object with an href string property).
This PR checks if the provided href is prefixed by / (indicating a relative path) and if so, prepends the valid "http://www.example.com" string to the path, which allows us to still use PHP's filter_var function with FILTER_VALIDATE_URL definition. Both absolute and relative URL's now pass in the test(s) and the relative URL is still validated by PHP internals.
The JSON API Spec does not explicitly define the structure of URL in a Link (either when the link value is a URL string or when the link value is an object with an
href
string property).The schema defines a link as
uri-reference
(https://github.com/json-api/json-api/blob/gh-pages/schema#L180) which may be relative or absolute as opposed touri
which would be absolute only*.The move from
uri
touri-reference
happened in this (merged) PR: https://github.com/json-api/json-api/pull/1169/filesThis PR checks if the provided href is prefixed by
/
(indicating a relative path) and if so, prepends the valid "http://www.example.com" string to the path, which allows us to still use PHP'sfilter_var
function withFILTER_VALIDATE_URL
definition. Both absolute and relative URL's now pass in the test(s) and the relative URL is still validated by PHP internals.