Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Make sure the href attribute is constructed correctly when trailing slash is used #139

Open
wants to merge 3 commits into
base: 3
Choose a base branch
from

Conversation

edwilde
Copy link
Contributor

@edwilde edwilde commented Oct 17, 2024

Description

Just something I spotted in passing, when Controller::add_trailing_slash is enabled the href in the XML output for API responses is incorrect.

This adds a couple of tests, one to replicate the issue and fixes the issue.

The tests don't cover all usage as that would require setting up a proper stub etc. and I simply didn't have time for that. The fix should be fairly risk free.

Manual testing steps

  • Enable trailing slashes: Controller::add_trailing_slash = true
  • Request an API resource using the XML formatter
  • See the href urls are constructed correctly and don't end in /.xml

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

…ling slash is used

Prior to the fix, when trailing slash is enabled the url output is incorrect; the second test fails because the href output contains: `/api/v1/SilverStripe-ORM-DataObject/1/.xml`.
/**
* Tests wrapper output of {@link XMLDataFormatter::convertDataObjectWithoutHeader()}
*/
public function testConvertDataObjectWithoutHeaderClassNameAttribute(): void
Copy link
Member

@emteknetnz emteknetnz Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two tests are basically identical, use a single test and use a @dataProvider and a bool $trailingSlash param.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I was being lazy 😪

Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry should have asked to target 3.0 so that it can be patched released immediately. You may need to rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants