umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.48k stars 2.69k forks source link

GetUniqueName for Umbraco NodeName doesn't consider 'multiple spaces' and can accidentally create clashing URLs #15850

Open marcemarc opened 8 months ago

marcemarc commented 8 months ago

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.0.1

Bug summary

This is a niche thing, only really mentioning it in case it's useful for a hackathon etc, it might not be fixable etc etc or deemed enough of an issue, it's not a showstopper.

When you create a NodeName in Umbraco or via the ContentService.CreateContent, if you give the node the same name as a node existing at the same level in the tree, then Umbraco will append (1) to the node name if a node with that name already exists. This ensures uniqueness of Urls (in old Umbraco this was a config setting and you could turn it off! :-P)

This is supercoool... but the niche thing, I've just noticed on a site, because a 'Member' can login and create a 'Case Study' and these Case Studies are all created underneath the 'Case Studies' section node is that a Member managed to create a 'Case Study' with a clashing URL!!!! How?

Well they called their case study 'Maths Enrichment'... ... the other case study was called 'Maths Enrichment'...

double space between the words !! (yes It took me a few minutes to find it)

Why is this a problem?

when it comes to creating the Url segment a double space is replaced by a single dash, so Maths Enrichment doesn't become /maths--enrichment, it becomes /maths-enrichment which clashes with the Url of the one without two spaces!

Now it's unlikely that an editor or Member will create a case study with double spaces in it.... looking at the DB, it's happened 17 times in 8 years...

But interested, should we leave 'as is' ???

or

when we get similar nodes to compare: github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs#L1003

image

should we strip spaces from the nodenames?

and then when we do the comparison...

https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/SimilarNodeName.cs#L37

image

take spaces into consideration - or perhaps use .ToUrlSegment() to capture other things that might not clash in nodename but that will strip when creating the Url?? in case there are other edge cases...

Specifics

Backoffice or ContentService.CreateContent

Steps to reproduce

Create a content item in Umbraco eg. 'Test Content' Remember it's name Create a content item at the same level, with the same name, but with loads of spaces 'Test Content' Umbraco allows you to save and publish both but the URLs generated for each clash /test-content

Expected result / actual result

I reckon by convention you'd expect the second item to become Test Content (1) when you save.... but is that toooooooo invasive, what if the editor wants to have spaces in the node name??? be a breaking change?

github-actions[bot] commented 8 months ago

Hi there @marcemarc!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:

NguyenThuyLan commented 3 months ago

Thanks @marcemarc for reporting this, I can confirm this is a bug with quite low priority. It should have appended a number to the path.

github-actions[bot] commented 3 months ago

Hi @marcemarc,

We're writing to let you know that we would love some help with this issue. We feel that this issue is ideal to flag for a community member to work on it. Once flagged here, folk looking for issues to work on will know to look at yours. Of course, please feel free work on this yourself ;-). If there are any changes to this status, we'll be sure to let you know.

For more information about issues and states, have a look at this blog post.

Thanks muchly, from your friendly Umbraco GitHub bot :-)