From 88e2cac0f8188a016682ca62c2675765d936186c Mon Sep 17 00:00:00 2001
From: Marcin Mielnicki <marcin.mielnicki@gmail.com>
Date: Sun, 5 Jan 2020 21:30:57 +0100
Subject: [PATCH] Exclude 'get' logo in load-simple-icons/fixes: logos:
 TypeError: Cannot read property '1' of null (#4488)

* Exclude 'get' key from simple icons

* Improved assertion readability

* A comment added in test
---
 lib/load-simple-icons.js      | 10 ++++------
 lib/load-simple-icons.spec.js | 29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 6 deletions(-)
 create mode 100644 lib/load-simple-icons.spec.js

diff --git a/lib/load-simple-icons.js b/lib/load-simple-icons.js
index 47af134356..976573d411 100644
--- a/lib/load-simple-icons.js
+++ b/lib/load-simple-icons.js
@@ -1,15 +1,13 @@
 'use strict'
 
-const simpleIcons = require('simple-icons')
+const originalSimpleIcons = require('simple-icons')
 const { svg2base64 } = require('./svg-helpers')
 
 function loadSimpleIcons() {
-  Object.keys(simpleIcons).forEach(key => {
+  const simpleIcons = {}
+  Object.keys(originalSimpleIcons).forEach(key => {
     const k = key.toLowerCase().replace(/ /g, '-')
-    if (k !== key) {
-      simpleIcons[k] = simpleIcons[key]
-      delete simpleIcons[key]
-    }
+    simpleIcons[k] = originalSimpleIcons[key]
     simpleIcons[k].base64 = {
       default: svg2base64(
         simpleIcons[k].svg.replace('<svg', `<svg fill="#${simpleIcons[k].hex}"`)
diff --git a/lib/load-simple-icons.spec.js b/lib/load-simple-icons.spec.js
new file mode 100644
index 0000000000..3b42044999
--- /dev/null
+++ b/lib/load-simple-icons.spec.js
@@ -0,0 +1,29 @@
+'use strict'
+
+const { expect } = require('chai')
+const loadSimpleIcons = require('./load-simple-icons')
+
+describe('loadSimpleIcons', function() {
+  let simpleIcons
+  before(function() {
+    simpleIcons = loadSimpleIcons()
+  })
+
+  it('prepares three color themes', function() {
+    expect(simpleIcons['sentry'].base64).to.have.all.keys(
+      'default',
+      'light',
+      'dark'
+    )
+  })
+
+  it('normalizes icon keys', function() {
+    // original key in the simple-icons is 'Linux Foundation'
+    expect(simpleIcons).to.include.key('linux-foundation')
+  })
+
+  // https://github.com/badges/shields/issues/4016
+  it('excludes "get" function provided by the simple-icons', function() {
+    expect(simpleIcons).to.not.have.property('get')
+  })
+})
-- 
GitLab