Fix invalidation path for post type without archive page #108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When an invalidation is submitted for post type that does not have an archive page, the invalidation paths submitted may include the path "://*". This results in a 400 bad request status from the CloudFront API. The issue can be traced to the parse_url function in classes/WP/Post.php. The function will accept a null or empty string for the URL. Doing so will cause the function to return the string "://". Possibly related to #107.
Since the calling function get_the_post_type_archive_links() is already written to handle a situation where parse_url returns an instance of WP_Error, I have updated parse_url to return a WP_Error object when the given url is empty or null. That appears to be the intended behavior from the existing code. As a result of this change, cache invalidations for post types without an archive page do not include the invalid path in the submission to CloudFront.
A unit test has been added to test/WP/Post_Test.php to validate that parse_url returns an instance of the WP_Error class when given an empty string.