Skip to content

Commit cd45701

Browse files
committed
Fix tidy warnings and add some tests
1 parent 4bbcdbe commit cd45701

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

app/helpers/format-email.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ var escape = Ember.Handlebars.Utils.escapeExpression;
44

55
function formatEmail(email) {
66
var formatted = email.match(/^(.*?)\s*(?:<(.*)>)?$/);
7-
var email = "";
7+
var ret = "";
88

9-
email += escape(formatted[1]);
9+
ret += escape(formatted[1]);
1010

1111
if (formatted[2]) {
12-
email = "<a href='mailto:" + escape(formatted[2]) + "'>" + email + "</a>";
12+
ret = "<a href='mailto:" + escape(formatted[2]) + "'>" + ret + "</a>";
1313
}
1414

15-
console.log(email);
16-
return email.htmlSafe();
15+
return ret.htmlSafe();
1716
}
1817

18+
19+
export {
20+
formatEmail
21+
};
22+
1923
export default Ember.Handlebars.makeBoundHelper(formatEmail);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {
2+
formatEmail
3+
} from 'cargo/helpers/format-email';
4+
5+
module('FormatEmailHelper');
6+
7+
// Replace this with your real tests.
8+
test('it works', function(assert) {
9+
assert.equal(formatEmail('foo'), 'foo');
10+
assert.equal(formatEmail('foo <foo@bar.com>').toString(),
11+
"<a href='mailto:foo@bar.com'>foo</a>");
12+
assert.equal(formatEmail('<script></script> <foo@bar.com>').toString(),
13+
"<a href='mailto:script&gt;&lt;/script&gt; &lt;foo@bar.com'></a>");
14+
assert.equal(formatEmail('').toString(), '');
15+
assert.equal(formatEmail('test <foo').toString(), 'test &lt;foo');
16+
});
17+

0 commit comments

Comments
 (0)