Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
0d32d318
Commit
0d32d318
authored
Jul 03, 2019
by
Luke Ward
Committed by
Paul Slaughter
Jul 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace slugifyWithHyphens with improved slugify function
parent
903227b0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
8 deletions
+35
-8
app/assets/javascripts/group.js
app/assets/javascripts/group.js
+2
-2
app/assets/javascripts/lib/utils/text_utility.js
app/assets/javascripts/lib/utils/text_utility.js
+9
-2
app/assets/javascripts/projects/project_new.js
app/assets/javascripts/projects/project_new.js
+2
-2
changelogs/unreleased/slugify.yml
changelogs/unreleased/slugify.yml
+5
-0
spec/frontend/lib/utils/text_utility_spec.js
spec/frontend/lib/utils/text_utility_spec.js
+17
-2
No files found.
app/assets/javascripts/group.js
View file @
0d32d318
import
$
from
'
jquery
'
;
import
{
slugify
WithHyphens
}
from
'
./lib/utils/text_utility
'
;
import
{
slugify
}
from
'
./lib/utils/text_utility
'
;
export
default
class
Group
{
constructor
()
{
...
...
@@ -14,7 +14,7 @@ export default class Group {
}
update
()
{
const
slug
=
slugify
WithHyphens
(
this
.
groupName
.
val
());
const
slug
=
slugify
(
this
.
groupName
.
val
());
this
.
groupPath
.
val
(
slug
);
}
...
...
app/assets/javascripts/lib/utils/text_utility.js
View file @
0d32d318
...
...
@@ -44,11 +44,18 @@ export const pluralize = (str, count) => str + (count > 1 || count === 0 ? 's' :
export
const
dasherize
=
str
=>
str
.
replace
(
/
[
_
\s]
+/g
,
'
-
'
);
/**
* Replaces whitespaces with hyphens
and converts to lower case
* Replaces whitespaces with hyphens
, convert to lower case and remove non-allowed special characters
* @param {String} str
* @returns {String}
*/
export
const
slugifyWithHyphens
=
str
=>
str
.
toLowerCase
().
replace
(
/
\s
+/g
,
'
-
'
);
export
const
slugify
=
str
=>
{
const
slug
=
str
.
trim
()
.
toLowerCase
()
.
replace
(
/
[^
a-zA-Z0-9_.-
]
+/g
,
'
-
'
);
return
slug
===
'
-
'
?
''
:
slug
;
};
/**
* Replaces whitespaces with underscore and converts to lower case
...
...
app/assets/javascripts/projects/project_new.js
View file @
0d32d318
import
$
from
'
jquery
'
;
import
{
addSelectOnFocusBehaviour
}
from
'
../lib/utils/common_utils
'
;
import
{
slugify
WithHyphens
}
from
'
../lib/utils/text_utility
'
;
import
{
slugify
}
from
'
../lib/utils/text_utility
'
;
import
{
s__
}
from
'
~/locale
'
;
let
hasUserDefinedProjectPath
=
false
;
...
...
@@ -34,7 +34,7 @@ const deriveProjectPathFromUrl = $projectImportUrl => {
};
const
onProjectNameChange
=
(
$projectNameInput
,
$projectPathInput
)
=>
{
const
slug
=
slugify
WithHyphens
(
$projectNameInput
.
val
());
const
slug
=
slugify
(
$projectNameInput
.
val
());
$projectPathInput
.
val
(
slug
);
};
...
...
changelogs/unreleased/slugify.yml
0 → 100644
View file @
0d32d318
---
title
:
Replace slugifyWithHyphens with improved slugify function
merge_request
:
30172
author
:
Luke Ward
type
:
fixed
spec/frontend/lib/utils/text_utility_spec.js
View file @
0d32d318
...
...
@@ -55,9 +55,24 @@ describe('text_utility', () => {
});
});
describe
(
'
slugifyWithHyphens
'
,
()
=>
{
describe
(
'
slugify
'
,
()
=>
{
it
(
'
should remove accents and convert to lower case
'
,
()
=>
{
expect
(
textUtils
.
slugify
(
'
João
'
)).
toEqual
(
'
jo-o
'
);
});
it
(
'
should replaces whitespaces with hyphens and convert to lower case
'
,
()
=>
{
expect
(
textUtils
.
slugifyWithHyphens
(
'
My Input String
'
)).
toEqual
(
'
my-input-string
'
);
expect
(
textUtils
.
slugify
(
'
My Input String
'
)).
toEqual
(
'
my-input-string
'
);
});
it
(
'
should remove trailing whitespace and replace whitespaces within string with a hyphen
'
,
()
=>
{
expect
(
textUtils
.
slugify
(
'
a new project
'
)).
toEqual
(
'
a-new-project
'
);
});
it
(
'
should only remove non-allowed special characters
'
,
()
=>
{
expect
(
textUtils
.
slugify
(
'
test!_pro-ject~
'
)).
toEqual
(
'
test-_pro-ject-
'
);
});
it
(
'
should squash multiple hypens
'
,
()
=>
{
expect
(
textUtils
.
slugify
(
'
test!!!!_pro-ject~
'
)).
toEqual
(
'
test-_pro-ject-
'
);
});
it
(
'
should return empty string if only non-allowed characters
'
,
()
=>
{
expect
(
textUtils
.
slugify
(
'
здрасти
'
)).
toEqual
(
''
);
});
});
...
...
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