luyadev / luya-module-cms

The LUYA CMS module provides a full functional CMS for adding contents based on blocks.
https://luya.io
MIT License
33 stars 46 forks source link

Filter invalid characters from URL slug #196

Closed cebe closed 9 months ago

cebe commented 5 years ago

What steps will reproduce the problem?

When creating a new page, the URL slug is filled from the page title.

If I fill How and Why?, the URL defaults to how-and-why?, when URL Path segment contains a ? the page can not be loaed.

What is the expected result?

Invalid characters should be replaced/filtered, or validation should apply to warn users about it.

What do you get instead? (A Screenshot can help us a lot!)

Bildschirmfoto von »2019-05-28 11-49-07«

Additional infos

Q A
LUYA Version core 1.0.18, cms 1.0.9
PHP Version 7.1.7
Platform Apache
Operating system Linux Server
nadar commented 5 years ago

If you say when URL Path segment contains a ? the page can not be loaed. do you mean frontend? or do you get a javascript error?

There where a few discussions regarding url paths/slugs - because it seems that transliteration is not helpfull in url context when talking about search engines:

https://github.com/luyadev/luya/issues/1557

cebe commented 5 years ago

Frontend can not load the page. The generated URL is http://exampl.com/de/features/how-and-why? which will result in the request being http://exampl.com/de/features/how-and-why (because ? is the query param delimiter) which then redirects to http://exampl.com/de/features.

nadar commented 5 years ago

Ok sure ? should not be a valid char in this context, otherwise it should %3F instead of ?.

hbugdoll commented 9 months ago

Ok sure ? should not be a valid char in this context, otherwise it should %3F instead of ?.

% is currently stripped afterwards, so URL-encoded characters are currently not possible. http://exampl.com/de/features/how-and-why3f will generated in this case.

But there are some more problems:

I have created an overview...

Character Resolve Error (404) Error on Input Stripped Replaced Reserved (RFC 3986)
? X X
# X X
/ X (X) X
\ X (X)
_ X
% X
. X
< > X
{ } X
\| X
` X
= X (X) X
+ X X
X
X
whitespace X
! X
$ X
& X
' X
( ) X
[ ] X
* X
, X
: X
; X
@ X
nadar commented 9 months ago

I am going to close this issue because:

If you think this is still important or there are more/new informations. Please reopen the issue and let us know.

If this is a problem or a feature you like to discuss, join our discussion: LUYA discussions. We try to keep our issue tracker as clean as possible in order to focus on active issues.

hbugdoll commented 9 months ago

core/helpers/Inflector::slug() needs some improvements:

nadar commented 9 months ago

https://github.com/luyadev/luya-module-cms/blob/master/src/models/NavItem.php#L168

if transliteration would be enabled, we would have much much less problems, it would follow the original yii2 inflector rules. Maybe the cms should just have a module config option whether transliteration should be enabled or not.

https://github.com/luyadev/yii-helpers/blob/master/src/helpers/Inflector.php#L38

hbugdoll commented 9 months ago

Maybe the cms should just have a module config option whether transliteration should be enabled or not.

This would be added value. My suggestion: https://github.com/hbugdoll/luya-module-cms/commit/423ccaf921909b7b54467c9b7ca8e12e2faaa85e