Fix shortenUrl helper to not crash when URL doesn't include any "/".

This commit is contained in:
macournoyer 2014-02-05 22:36:26 -05:00
parent 3a6c3ee65d
commit 8bf872e92e

View File

@ -106,10 +106,11 @@ Handlebars.registerHelper('titledLinkTo', function(name, object) {
@for Handlebars @for Handlebars
**/ **/
Handlebars.registerHelper('shortenUrl', function(property, options) { Handlebars.registerHelper('shortenUrl', function(property, options) {
var url; var url, matches;
url = Ember.Handlebars.get(this, property, options); url = Ember.Handlebars.get(this, property, options);
// Remove trailing slash if it's a top level URL // Remove trailing slash if it's a top level URL
if (url.match(/\//g).length === 3) { matches = url.match(/\//g);
if (matches && matches.length === 3) {
url = url.replace(/\/$/, ''); url = url.replace(/\/$/, '');
} }
url = url.replace(/^https?:\/\//, ''); url = url.replace(/^https?:\/\//, '');