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 Validate Category / Tag Titles #700

Closed
wants to merge 2 commits into from

Conversation

freezernick
Copy link

Closes #695

Co-authored-by: Michal Kleiner <[email protected]>
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

@silverstripe/core-team
What's our thoughts about this in regards to semver?
Specifically, changing the validation rules for whether an empty value is valid or not.

On one hand, it seems like there's no valid reason to have an empty category/tag - but on the other, someone could very well be going BlogTag::create()->write() in a unit test, if the value of the tag doesn't matter for that test.

@@ -72,6 +72,10 @@ public function validate()
$validation->addError($this->getDuplicateError(), self::DUPLICATE_EXCEPTION);
}

if (empty($this->Title)) {
$validation->addError($this->getEmptyTitleError(), self::EMPTY_TITLE_EXCEPTION);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$validation->addError($this->getEmptyTitleError(), self::EMPTY_TITLE_EXCEPTION);
$validation->addError($this->getEmptyTitleError(), self::EMPTY_TITLE_EXCEPTION ?? 'EMPTY_TITLE');

The constant won't be declared on any custom classes that use this trait, and requiring it to be added is technically a breaking change.

Note: Please test that this actually works - I've not tried the null coalescing operator in this context before. I think it'll work but it'll pay to check.

Copy link
Member

@emteknetnz emteknetnz Apr 11, 2023

Choose a reason for hiding this comment

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

Yikes, shouldn't be calling self::<const> on a trait. Not a great choice when this was made back in the day

I don't think null coalescing works here

class C { function F(){ var_dump(self::Z ?? 'default'); } }; (new C)->F();
// PHP Warning:  Uncaught Error: Undefined constant C::Z in php shell cod

@emteknetnz
Copy link
Member

someone could very well be going BlogTag::create()->write() in a unit test

No one other than core team is going to write new unit tests, and the existing unit tests are green on this PR, so I see no reason to be concerned here.

@GuySartorelli
Copy link
Member

No one other than core team is going to write new unit tests

People write unit tests for their own projects and modules all the time. It's not super likely those tests will rely on blog tags or categories but it's also not impossible.

@emteknetnz
Copy link
Member

emteknetnz commented Apr 11, 2023

Oh sorry I meant "No one other than core team is going to write new unit tests for the blog module" :-)

What's the concern? That a project will create their own unit test that instantiates a their own subclass of a BlogCategory or BlogTag with a blank Title? That's seems extremely unlikely. And even if they did and their test fails, they'll get a pretty clear Title must not be empty error which should be easy to trace back, so fixing the broken tests should require minimal effort.

While we're very strict with respecting semver API in minor releases, historically we've been somewhat lenient/pragmatic with behavioral changes, including changes to default configuration values. This PR seems at the low end of changes within a minor.

@michalkleiner
Copy link
Contributor

What's our thoughts about this in regards to semver? Specifically, changing the validation rules for whether an empty value is valid or not.

On one hand, it seems like there's no valid reason to have an empty category/tag - but on the other, someone could very well be going BlogTag::create()->write() in a unit test, if the value of the tag doesn't matter for that test.

Not bothered by this particular change, I agree with Steve on this.

@GuySartorelli
Copy link
Member

Sweet, just wanted to get the general feeling about it, since I was on the fence about it.
There's problems with how the constant is being applied, but sounds like the general approach is okay.

@GuySartorelli
Copy link
Member

@freezernick Are you still interested in this pull request being merged? If so, please make changes to how the constant is applied as requested above.

@GuySartorelli
Copy link
Member

I'm closing this due to inactivity. If you want to work on it again I'll be happy to reopen it, or you can open a new pull request from scratch.

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.

The user can create and save a Blog Category or Blog Tag without a Title
4 participants