Skip to content

Fix slug bug when using non alphabet title #136

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

Closed
wants to merge 1 commit into from

Conversation

bravewood
Copy link
Contributor

If you create a post using non alphabet title, the slug of this new post will be set empty.
http://127.0.0.1:8000/en/admin/post/new

For example:
In case I use 'русский язык' for a title of a new post, the post will be create with no error.
But, the slug will be set empty.
Therefore, indexAction in BlogController will return an error like this:
An exception has been thrown during the rendering of a template ("Parameter "slug" for route "blog_post" must match "[^/]++" ("" given) to generate a corresponding URL.") in blog/index.html.twig at line 9.

This pull request fix the problem.

@javiereguiluz
Copy link
Member

@bravewood thanks for reporting this error. The problem of the proposed solution is that it uses mb_*() functions and we don't want to make them a mandatory requirement for this project. Maybe it's time to use a real slugger to avoid any issue? (for example this one: https://github.com/javiereguiluz/easyslugger ^.^)

@bravewood
Copy link
Contributor Author

@javiereguiluz thanks for replying me. I agree with you. I understand the slugging contains a difficult problem. My PR is not a perfect solution for this problem, so it is necessary to use a third party slug library to avoid this problem. I think it's better that Symfony demo uses a slug library than my PR.

@stof
Copy link
Member

stof commented Aug 10, 2015

a solution could be to rely on https://github.com/Behat/Transliterator/ to make the transliteration

@bravewood
Copy link
Contributor Author

I have no idea which library to be selected for this project.
If you could choose one slug library, I'd change this PR.
Thanks.

@javiereguiluz
Copy link
Member

I'm closing this in favor of #389. I'm sorry it took us so long to fix this.

javiereguiluz added a commit that referenced this pull request Oct 14, 2016
This PR was squashed before being merged into the master branch (closes #389).

Discussion
----------

Made the slugger compatible with every language

In the Symfony Installer we recently made a change to forbid any non-Latin character in the project names ([see details](symfony/symfony-installer#278)). This is needed because Composer itself requires that for package names.

In the Symfony Demo app we had a similar problem with the slugs of the blog posts. We removed any non-Latin character ... but that caused bugs like #136. I propose to change the slugger completely and accept any character.

For example, you can now create this blog post:

![backend_post](https://cloud.githubusercontent.com/assets/73419/19352609/b582a714-9160-11e6-81de-8e5130f1ec78.png)

And the blog listing no longer displays an error:

![blog_post](https://cloud.githubusercontent.com/assets/73419/19352619/bfbd87d0-9160-11e6-89fa-ca60aee1b5fe.png)

And the URL is perfectly fine although it contains non-Latin chars:

![url-post](https://cloud.githubusercontent.com/assets/73419/19352634/c9fc89c6-9160-11e6-999c-346b4da78653.png)

Commits
-------

161b508 Made the slugger compatible with every language
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants