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
ee32d36f
Commit
ee32d36f
authored
Aug 18, 2020
by
Enrique Alcantara
Committed by
jerasmus
Sep 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add getURLOrigin utility
parent
ef5e4f47
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
app/assets/javascripts/lib/utils/url_utility.js
app/assets/javascripts/lib/utils/url_utility.js
+13
-0
spec/frontend/lib/utils/url_utility_spec.js
spec/frontend/lib/utils/url_utility_spec.js
+19
-0
No files found.
app/assets/javascripts/lib/utils/url_utility.js
View file @
ee32d36f
...
...
@@ -444,3 +444,16 @@ export function getHTTPProtocol(url) {
export
function
stripPathTail
(
path
=
''
)
{
return
path
.
replace
(
/
[^/]
+$/
,
''
);
}
export
function
getURLOrigin
(
url
)
{
if
(
!
url
)
{
return
window
.
location
.
origin
;
}
try
{
return
new
URL
(
url
).
origin
;
}
catch
(
e
)
{
return
null
;
}
}
spec/frontend/lib/utils/url_utility_spec.js
View file @
ee32d36f
...
...
@@ -814,4 +814,23 @@ describe('URL utility', () => {
expect
(
urlUtils
.
stripPathTail
(
path
)).
toBe
(
expected
);
});
});
describe
(
'
getURLOrigin
'
,
()
=>
{
it
(
'
when no url passed, returns correct origin from window location
'
,
()
=>
{
const
origin
=
'
https://foo.bar
'
;
setWindowLocation
({
origin
});
expect
(
urlUtils
.
getURLOrigin
()).
toBe
(
origin
);
});
it
.
each
`
url | expectation
${
'
not-a-url
'
}
|
${
null
}
${
'
wss://example.com
'
}
|
${
'
wss://example.com
'
}
${
'
https://foo.bar/foo/bar
'
}
|
${
'
https://foo.bar
'
}
`
(
'
returns correct origin for $url
'
,
({
url
,
expectation
})
=>
{
expect
(
urlUtils
.
getURLOrigin
(
url
)).
toBe
(
expectation
);
});
});
});
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