Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
diaspora
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gigadoc 2
diaspora
Commits
f4ea138a
Unverified
Commit
f4ea138a
authored
Apr 10, 2018
by
Benjamin Neff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't return a SafeString after truncate
parent
d0313756
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
7 deletions
+20
-7
Changelog.md
Changelog.md
+4
-0
app/assets/javascripts/app/helpers/truncate.js
app/assets/javascripts/app/helpers/truncate.js
+4
-7
spec/javascripts/app/helpers/truncate_spec.js
spec/javascripts/app/helpers/truncate_spec.js
+12
-0
No files found.
Changelog.md
View file @
f4ea138a
# 0.7.4.1
Fixes a possible cross-site scripting issue with maliciously crafted OpenGraph metadata.
# 0.7.4.0
## Refactor
...
...
app/assets/javascripts/app/helpers/truncate.js
View file @
f4ea138a
(
function
()
{
app
.
helpers
.
truncate
=
function
(
passedString
,
length
)
{
if
(
passedString
===
null
||
passedString
===
undefined
)
{
if
(
passedString
===
null
||
passedString
===
undefined
||
passedString
.
length
<
length
)
{
return
passedString
;
}
if
(
passedString
.
length
>
length
)
{
var
lastBlank
=
passedString
.
lastIndexOf
(
'
'
,
length
);
var
trimstring
=
passedString
.
substring
(
0
,
Math
.
min
(
length
,
lastBlank
));
return
new
Handlebars
.
SafeString
(
trimstring
+
"
...
"
);
}
return
new
Handlebars
.
SafeString
(
passedString
);
var
lastBlank
=
passedString
.
lastIndexOf
(
"
"
,
length
);
var
trimstring
=
passedString
.
substring
(
0
,
Math
.
min
(
length
,
lastBlank
));
return
trimstring
+
"
...
"
;
};
})();
spec/javascripts/app/helpers/truncate_spec.js
View file @
f4ea138a
...
...
@@ -6,4 +6,16 @@ describe("app.helpers.truncate", function() {
it
(
"
handles undefined
"
,
function
()
{
expect
(
app
.
helpers
.
truncate
(
undefined
,
123
)).
toEqual
(
undefined
);
});
it
(
"
returns a short string
"
,
function
()
{
expect
(
app
.
helpers
.
truncate
(
"
Some text
"
,
10
)).
toEqual
(
"
Some text
"
);
});
it
(
"
trims a long string at a space
"
,
function
()
{
expect
(
app
.
helpers
.
truncate
(
"
Some very long text
"
,
10
)).
toEqual
(
"
Some very ...
"
);
});
it
(
"
returns a string
"
,
function
()
{
expect
(
typeof
app
.
helpers
.
truncate
(
"
Some very long text
"
,
10
)).
toEqual
(
"
string
"
);
});
});
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