Skip to content
This repository

Fix capitalisation of zero length strings #50

Open
wants to merge 1 commit into from

1 participant

Greg Miell
Greg Miell
GothAck commented

Capitalisation of zero length strings tried to uppercase undefined due to typeof str[0] === 'undefined', .charAt(0) fixes this by returning an empty string if the char does not exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 23, 2012
Greg Miell GothAck Fix capitalisation of zero length strings b5d4441
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 2 additions and 2 deletions. Show diff stats Hide diff stats

  1. +2 2 lib/filters.js
4 lib/filters.js
@@ -27,7 +27,7 @@ exports.last = function(obj) {
27 27
28 28 exports.capitalize = function(str){
29 29 str = String(str);
30   - return str[0].toUpperCase() + str.substr(1, str.length);
  30 + return str.charAt(0).toUpperCase() + str.substr(1, str.length);
31 31 };
32 32
33 33 /**
@@ -195,4 +195,4 @@ exports.get = function(obj, prop){
195 195 */
196 196 exports.json = function(obj){
197 197 return JSON.stringify(obj);
198   -};
  198 +};

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.