Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capitalization with empty keys #1625

Merged
merged 1 commit into from
Apr 1, 2018
Merged

Capitalization with empty keys #1625

merged 1 commit into from
Apr 1, 2018

Conversation

PyvesB
Copy link
Member

@PyvesB PyvesB commented Mar 30, 2018

This pull request addresses issue #1606. We now also have some tests for the social badge template!

@shields-ci
Copy link

Messages
📖

✨ Thanks for your contribution to Shields, @PyvesB!

Generated by 🚫 dangerJS

@RedSparr0w
Copy link
Member

RedSparr0w commented Mar 31, 2018

Thanks for this PR, you've been making a ton of progress through all the errors recently!
Unfortunately i don't think this will fix #1606
for undefined it will still throw Uncaught TypeError: Cannot read property 'charAt' of undefined
for numbers it will throw Uncaught TypeError: s.charAt is not a function

something like this should work:

-function capitalize(s) {
+function capitalize(s = '') {
+	s = '' + s;
	return s.charAt(0).toUpperCase() + s.slice(1);
}

Output:

capitalize(undefined); // ""
capitalize(2); // "2"
capitalize(false); // "False"
capitalize('test'); // "Test"

Edit:

Didn't realise it was undefined due to trying to get the first character using [0] of '', nice work!
👍

@PyvesB
Copy link
Member Author

PyvesB commented Mar 31, 2018

Yes, the input s can be empty (which was causing the crash), but cannot itself be undefined due to a string coercion step before the call to capitalize:

  // String coercion.
  text = text.map(value => '' + value); 

@PyvesB PyvesB merged commit c5884b1 into badges:master Apr 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants