Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nginx-push-stream-module
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
nginx-push-stream-module
Commits
aebc563f
Commit
aebc563f
authored
Nov 18, 2012
by
Wandenberg Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding tests to parseJSON method
parent
4e55a64f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
2 deletions
+80
-2
pushstream.js
misc/js/pushstream.js
+2
-2
PushStreamUtilsSpec.js
test/spec/javascripts/PushStreamUtilsSpec.js
+78
-0
No files found.
misc/js/pushstream.js
View file @
aebc563f
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
};
};
var
parseJSON
=
function
(
data
)
{
var
parseJSON
=
function
(
data
)
{
if
(
typeof
data
!==
"
string
"
||
!
data
)
{
if
(
!
data
||
!
isString
(
data
)
)
{
return
null
;
return
null
;
}
}
...
@@ -305,7 +305,7 @@
...
@@ -305,7 +305,7 @@
var
message
=
{
var
message
=
{
id
:
msg
[
keys
.
jsonIdKey
],
id
:
msg
[
keys
.
jsonIdKey
],
channel
:
msg
[
keys
.
jsonChannelKey
],
channel
:
msg
[
keys
.
jsonChannelKey
],
data
:
(
typeof
(
msg
[
keys
.
jsonDataKey
])
==
'
string
'
)
?
unescapeText
(
msg
[
keys
.
jsonDataKey
])
:
msg
[
keys
.
jsonDataKey
],
data
:
isString
(
msg
[
keys
.
jsonDataKey
])
?
unescapeText
(
msg
[
keys
.
jsonDataKey
])
:
msg
[
keys
.
jsonDataKey
],
tag
:
msg
[
keys
.
jsonTagKey
],
tag
:
msg
[
keys
.
jsonTagKey
],
time
:
msg
[
keys
.
jsonTimeKey
],
time
:
msg
[
keys
.
jsonTimeKey
],
eventid
:
msg
[
keys
.
jsonEventIdKey
]
||
""
eventid
:
msg
[
keys
.
jsonEventIdKey
]
||
""
...
...
test/spec/javascripts/PushStreamUtilsSpec.js
View file @
aebc563f
...
@@ -11,6 +11,84 @@ describe("PushStreamUtils", function() {
...
@@ -11,6 +11,84 @@ describe("PushStreamUtils", function() {
beforeEach
(
function
()
{
beforeEach
(
function
()
{
});
});
describe
(
"
when parse JSON
"
,
function
()
{
it
(
"
should return null when data is null
"
,
function
()
{
expect
(
parseJSON
(
null
)).
toBe
(
null
);
});
it
(
"
should return null when data is undefined
"
,
function
()
{
expect
(
parseJSON
(
undefined
)).
toBe
(
null
);
});
it
(
"
should return null when data is not a string
"
,
function
()
{
expect
(
parseJSON
({})).
toBe
(
null
);
});
if
(
window
.
JSON
)
{
describe
(
"
when have a default implementation for JSON.parse
"
,
function
()
{
var
jsonImplementation
=
null
;
beforeEach
(
function
()
{
jsonImplementation
=
window
.
JSON
;
// window.JSON = null;
});
afterEach
(
function
()
{
window
.
JSON
=
jsonImplementation
;
});
it
(
"
should use the browser default implementation when available
"
,
function
()
{
spyOn
(
window
.
JSON
,
"
parse
"
);
parseJSON
(
'
{"a":1}
'
)
expect
(
window
.
JSON
.
parse
).
toHaveBeenCalledWith
(
'
{"a":1}
'
);
});
it
(
"
should parse a well formed json string
"
,
function
()
{
expect
(
parseJSON
(
'
{"a":1}
'
)[
"
a
"
]).
toBe
(
1
);
});
it
(
"
should parse when the string has leading spaces
"
,
function
()
{
expect
(
parseJSON
(
'
{"a":1}
'
)[
"
a
"
]).
toBe
(
1
);
});
it
(
"
should parse when the string has trailing spaces
"
,
function
()
{
expect
(
parseJSON
(
'
{"a":1}
'
)[
"
a
"
]).
toBe
(
1
);
});
it
(
"
should raise error when string is a invalid json
"
,
function
()
{
expect
(
function
()
{
parseJSON
(
'
{"a":1[]}
'
)
}).
toThrow
(
'
Invalid JSON: {"a":1[]}
'
);
});
});
}
describe
(
"
when do not have a default implementation for JSON.parse
"
,
function
()
{
var
jsonImplementation
=
null
;
beforeEach
(
function
()
{
jsonImplementation
=
window
.
JSON
;
window
.
JSON
=
null
;
});
afterEach
(
function
()
{
window
.
JSON
=
jsonImplementation
;
});
it
(
"
should parse a well formed json string
"
,
function
()
{
expect
(
parseJSON
(
'
{"a":1}
'
)[
"
a
"
]).
toBe
(
1
);
});
it
(
"
should parse when the string has leading spaces
"
,
function
()
{
expect
(
parseJSON
(
'
{"a":1}
'
)[
"
a
"
]).
toBe
(
1
);
});
it
(
"
should parse when the string has trailing spaces
"
,
function
()
{
expect
(
parseJSON
(
'
{"a":1}
'
)[
"
a
"
]).
toBe
(
1
);
});
it
(
"
should raise error when string is a invalid json
"
,
function
()
{
expect
(
function
()
{
parseJSON
(
'
{"a":1[]}
'
)
}).
toThrow
(
'
Invalid JSON: {"a":1[]}
'
);
});
});
});
describe
(
"
when extract xss domain
"
,
function
()
{
describe
(
"
when extract xss domain
"
,
function
()
{
it
(
"
should return the ip address when domain is only an ip
"
,
function
()
{
it
(
"
should return the ip address when domain is only an ip
"
,
function
()
{
expect
(
extract_xss_domain
(
"
201.10.32.52
"
)).
toBe
(
"
201.10.32.52
"
);
expect
(
extract_xss_domain
(
"
201.10.32.52
"
)).
toBe
(
"
201.10.32.52
"
);
...
...
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