Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
d72663e0
Unverified
Commit
d72663e0
authored
Feb 27, 2018
by
Nicolas Widart
Committed by
GitHub
Feb 27, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #456 from darron1217/issue#455
Fix for Issue #455 (Adding support for UTF-8 slug)
parents
8bb3cdc4
8e8bc6d2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
2 deletions
+37
-2
TaggableTraitTest.php
Modules/Tag/Tests/Integration/TaggableTraitTest.php
+21
-0
TaggableTrait.php
Modules/Tag/Traits/TaggableTrait.php
+16
-2
No files found.
Modules/Tag/Tests/Integration/TaggableTraitTest.php
View file @
d72663e0
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Modules\Tag\Tests\Integration
;
namespace
Modules\Tag\Tests\Integration
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Str
;
use
Modules\Page\Entities\Page
;
use
Modules\Page\Entities\Page
;
use
Modules\Page\Repositories\PageRepository
;
use
Modules\Page\Repositories\PageRepository
;
use
Modules\Tag\Repositories\TagRepository
;
use
Modules\Tag\Repositories\TagRepository
;
...
@@ -132,6 +133,26 @@ class TaggableTraitTest extends BaseTestCase
...
@@ -132,6 +133,26 @@ class TaggableTraitTest extends BaseTestCase
$this
->
assertCount
(
3
,
Page
::
allTags
()
->
get
());
$this
->
assertCount
(
3
,
Page
::
allTags
()
->
get
());
}
}
/** @test */
public
function
it_generates_slug_like_original_str_slug
()
{
$page
=
$this
->
createPage
();
$this
->
assertEquals
(
Str
::
slug
(
'hello world'
),
$page
->
generateTagSlug
(
'hello world'
));
$this
->
assertEquals
(
Str
::
slug
(
'hello world'
),
$page
->
generateTagSlug
(
'hello-world'
));
$this
->
assertEquals
(
Str
::
slug
(
'hello_world'
),
$page
->
generateTagSlug
(
'hello_world'
));
$this
->
assertEquals
(
Str
::
slug
(
'hello_world'
,
'_'
),
$page
->
generateTagSlug
(
'hello_world'
,
'_'
));
$this
->
assertEquals
(
Str
::
slug
(
'user@host'
),
$page
->
generateTagSlug
(
'user@host'
));
}
/** @test */
public
function
it_gets_pages_with_non_latin_tags
()
{
$this
->
createPage
([
'한글 태그'
]);
$this
->
assertCount
(
1
,
Page
::
whereTag
([
'한글-태그'
])
->
get
());
}
private
function
createPage
(
array
$tags
=
[])
private
function
createPage
(
array
$tags
=
[])
{
{
return
$this
->
page
->
create
([
return
$this
->
page
->
create
([
...
...
Modules/Tag/Traits/TaggableTrait.php
View file @
d72663e0
...
@@ -204,8 +204,22 @@ trait TaggableTrait
...
@@ -204,8 +204,22 @@ trait TaggableTrait
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
p
rotected
function
generateTagSlug
(
$name
)
p
ublic
function
generateTagSlug
(
$name
,
$separator
=
'-'
)
{
{
return
str_slug
(
$name
);
// Convert all dashes/underscores into separator
$flip
=
$separator
==
'-'
?
'_'
:
'-'
;
$name
=
preg_replace
(
'!['
.
preg_quote
(
$flip
)
.
']+!u'
,
$separator
,
$name
);
// Replace @ with the word 'at'
$name
=
str_replace
(
'@'
,
$separator
.
'at'
.
$separator
,
$name
);
// Remove all characters that are not the separator, letters, numbers, or whitespace.
$name
=
preg_replace
(
'![^'
.
preg_quote
(
$separator
)
.
'\pL\pN\s]+!u'
,
''
,
mb_strtolower
(
$name
));
// Replace all separator characters and whitespace by a single separator
$name
=
preg_replace
(
'!['
.
preg_quote
(
$separator
)
.
'\s]+!u'
,
$separator
,
$name
);
return
trim
(
$name
,
$separator
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment