From 08b5f4bb355bc2e7988e745ac91b2c9bd7ad4a02 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Wed, 16 May 2018 11:32:55 -0500 Subject: [PATCH] always lowercase mode and name props --- src/components/icon/icon.spec.ts | 4 ++++ src/components/icon/icon.tsx | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/icon/icon.spec.ts b/src/components/icon/icon.spec.ts index fe21236a..e51a0e7b 100644 --- a/src/components/icon/icon.spec.ts +++ b/src/components/icon/icon.spec.ts @@ -146,6 +146,10 @@ describe('getName', () => { expect(icon.getName('md-some-name', '', '', '')).toBe('md-some-name'); }); + it('always lowercase name and mode', () => { + expect(icon.getName('SOME-NAME', 'IOS', '', '')).toBe('ios-some-name'); + }); + it('default md name w/out mode, ios or md', () => { expect(icon.getName('some-name', '', '', '')).toBe('md-some-name'); }); diff --git a/src/components/icon/icon.tsx b/src/components/icon/icon.tsx index b48a1505..4d3d2d6e 100755 --- a/src/components/icon/icon.tsx +++ b/src/components/icon/icon.tsx @@ -206,7 +206,7 @@ function getSvgContent(url: string) { export function getName(name: string, mode: string, ios: string, md: string) { // default to "md" if somehow the mode wasn't set - mode = mode || 'md'; + mode = (mode || 'md').toLowerCase(); // if an icon was passed in using the ios or md attributes // set the iconName to whatever was passed in @@ -219,7 +219,7 @@ export function getName(name: string, mode: string, ios: string, md: string) { } else if (name && !(/^md-|^ios-|^logo-/.test(name))) { // this does not have one of the defaults // so lets auto add in the mode prefix for them - name = mode + '-' + name; + name = mode + '-' + name.toLowerCase(); } if (typeof name !== 'string' || name.trim() === '') { @@ -227,7 +227,7 @@ export function getName(name: string, mode: string, ios: string, md: string) { } // only allow alpha characters and dash - const invalidChars = name.replace(/[a-z]|-|\d/g, ''); + const invalidChars = name.replace(/[a-z]|-|\d/gi, ''); if (invalidChars !== '') { return null; }