Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
5f514cb7
...
5f514cb715780be03a24d4cae0ab12d8fc8246d5
authored
2013-03-13 22:24:35 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixes #414 - better utils.cleanUrl()
1 parent
beb33963
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
10 deletions
modules/utils.js
tests/suites/utils.js
modules/utils.js
View file @
5f514cb
...
...
@@ -61,23 +61,19 @@ function betterTypeOf(input) {
exports
.
betterTypeOf
=
betterTypeOf
;
/**
* Cleans a passed URL
if it lacks a slash at the end when a sole domain is used
.
* Cleans a passed URL.
*
* @param String url An HTTP URL
* @return String
*/
function
cleanUrl
(
url
)
{
"use strict"
;
var
parts
=
/
(
https
?)
:
\/\/(
.*
)
/i
.
exec
(
url
);
if
(
!
parts
)
{
if
(
url
.
indexOf
(
'/'
)
===
0
)
{
return
url
;
}
var
protocol
=
parts
[
1
];
var
subparts
=
parts
[
2
].
split
(
'/'
);
if
(
subparts
.
length
===
1
)
{
return
format
(
"%s://%s/"
,
protocol
,
subparts
[
0
]);
}
return
url
;
var
a
=
document
.
createElement
(
'a'
);
a
.
href
=
url
;
return
a
.
href
;
}
exports
.
cleanUrl
=
cleanUrl
;
...
...
tests/suites/utils.js
View file @
5f514cb
...
...
@@ -24,7 +24,7 @@ casper.test.begin('utils.betterTypeOf() tests', 10, function(test) {
test
.
done
();
});
casper
.
test
.
begin
(
'utils.cleanUrl() tests'
,
1
0
,
function
(
test
)
{
casper
.
test
.
begin
(
'utils.cleanUrl() tests'
,
1
1
,
function
(
test
)
{
var
testCases
=
{
'http://google.com/'
:
'http://google.com/'
,
'http://google.com'
:
'http://google.com/'
,
...
...
@@ -34,6 +34,7 @@ casper.test.begin('utils.cleanUrl() tests', 10, function(test) {
'https://google.com'
:
'https://google.com/'
,
'https://www.google.com/'
:
'https://www.google.com/'
,
'https://www.google.com/?plop=2'
:
'https://www.google.com/?plop=2'
,
'https://www.google.com?plop=2'
:
'https://www.google.com/?plop=2'
,
'file:///Users/toto/toto.html'
:
'file:///Users/toto/toto.html'
,
'/100'
:
'/100'
};
...
...
Please
register
or
sign in
to post a comment