From 0fedee8f806f52cce63289ba0dba9a78693eab37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Rodr=C3=ADguez?= Date: Thu, 8 Feb 2018 20:52:50 +0000 Subject: [PATCH] No slug? Then no '-' separator! (#1351) * Stop using slug separator when there is no slug * Changing as per upstream requirements --- framework/core/js/forum/src/initializers/routes.js | 3 ++- framework/core/js/lib/utils/string.js | 2 +- framework/core/src/Util/Str.php | 2 +- framework/core/views/frontend/content/index.blade.php | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/framework/core/js/forum/src/initializers/routes.js b/framework/core/js/forum/src/initializers/routes.js index c319b3d1a..0a2adc6f6 100644 --- a/framework/core/js/forum/src/initializers/routes.js +++ b/framework/core/js/forum/src/initializers/routes.js @@ -34,8 +34,9 @@ export default function(app) { * @return {String} */ app.route.discussion = (discussion, near) => { + const slug = discussion.slug(); return app.route(near && near !== 1 ? 'discussion.near' : 'discussion', { - id: discussion.id() + '-' + discussion.slug(), + id: discussion.id() + (slug.trim() ? '-' + slug : ''), near: near && near !== 1 ? near : undefined }); }; diff --git a/framework/core/js/lib/utils/string.js b/framework/core/js/lib/utils/string.js index 92ad98ae7..291e7bc7f 100644 --- a/framework/core/js/lib/utils/string.js +++ b/framework/core/js/lib/utils/string.js @@ -23,7 +23,7 @@ export function slug(string) { return string.toLowerCase() .replace(/[^a-z0-9]/gi, '-') .replace(/-+/g, '-') - .replace(/-$|^-/g, '') || '-'; + .replace(/-$|^-/g, ''); } /** diff --git a/framework/core/src/Util/Str.php b/framework/core/src/Util/Str.php index 258b8a75c..f8c7d6a67 100644 --- a/framework/core/src/Util/Str.php +++ b/framework/core/src/Util/Str.php @@ -28,6 +28,6 @@ class Str $str = preg_replace('/-+/', '-', $str); $str = preg_replace('/-$|^-/', '', $str); - return $str ?: '-'; + return $str; } } diff --git a/framework/core/views/frontend/content/index.blade.php b/framework/core/views/frontend/content/index.blade.php index 08a6cc492..d5c4040ab 100644 --- a/framework/core/views/frontend/content/index.blade.php +++ b/framework/core/views/frontend/content/index.blade.php @@ -7,7 +7,7 @@ @foreach ($document->data as $discussion)
  • {{ $discussion->attributes->title }}