Repository: showdownjs/showdown
Pull request #764 (2020-02-09 15:25:19)

fix: octocat emoji image location (2)
This commits introduces the changes intended by https://github.com/showdownjs/showdown/pull/706 but that were not in the PR. Seems like branches were mixed up :smile: 

TPXP: I added a test to make sure the used URL works. Feel free to remove it if you don't think it's needed (it was a gread `chai` workshop though :smiley: )
SyntaxRules: @TPXP can you rebase off master so we can check against the latest CI checks? Thank you for making a test to go along with this!

Patch:
diff --git a/src/helpers.js b/src/helpers.js
index 554369b..c45a0ae 100644
--- a/src/helpers.js
+++ b/src/helpers.js
@@ -1710,6 +1710,6 @@ showdown.helper.emojis = {
   'zzz':'\ud83d\udca4',
 
   /* special emojis :P */
-  'octocat':  '<img width="20" height="20" align="absmiddle" src="https://assets-cdn.github.com/images/icons/emoji/octocat.png">',
+  'octocat':  '<img width="20" height="20" align="absmiddle" src="https://github.githubassets.com/images/icons/emoji/octocat.png">',
   'showdown': '<img width="20" height="20" align="absmiddle" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAS1BMVEX///8jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS3b1q3b1q3b1q3b1q3b1q3b1q3b1q3b1q0565CIAAAAGXRSTlMAQHCAYCCw/+DQwPCQUBAwoHCAEP+wwFBgS2fvBgAAAUZJREFUeAHs1cGy7BAUheFFsEDw/k97VTq3T6ge2EmdM+pvrP6Iwd74XV9Kb52xuMU4/uc1YNgZLFOeV8FGdhGrNk5SEgUyPxAEdj4LlMRDyhVAMVEa2M7TBSeVZAFPdqHgzSZJwPKgcLFLAooHDJo4EDCw4gAtBoJA5UFj4Ng5LOGLwVXZuoIlji/jeQHFk7+baHxrCjeUwB9+s88KndvlhcyBN5BSkYNQIVVb4pV+Npm7hhuKDs/uMP5KxT3WzSNNLIuuoDpMmuAVMruMSeDyQBi24DTr43LAY7ILA1QYaWkgfHzFthYYzg67SQsCbB8GhJUEGCtO9n0rSaCLxgJQjS/JSgMTg2eBDEHAJ+H350AsjYNYscrErgI2e/l+mdR967TCX/v6N0EhPECYCP0i+IAoYQOE8BogNhQMEMdrgAQWHaMAAGi5I5euoY9NAAAAAElFTkSuQmCC">'
 };


Test patch:
diff --git a/test/functional/makehtml/cases/features/emojis/special.html b/test/functional/makehtml/cases/features/emojis/special.html
index b591c21..4b11284 100644
--- a/test/functional/makehtml/cases/features/emojis/special.html
+++ b/test/functional/makehtml/cases/features/emojis/special.html
@@ -1,2 +1,2 @@
 <p>this is showdown's emoji <img width="20" height="20" align="absmiddle" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAS1BMVEX///8jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS3b1q3b1q3b1q3b1q3b1q3b1q3b1q3b1q0565CIAAAAGXRSTlMAQHCAYCCw/+DQwPCQUBAwoHCAEP+wwFBgS2fvBgAAAUZJREFUeAHs1cGy7BAUheFFsEDw/k97VTq3T6ge2EmdM+pvrP6Iwd74XV9Kb52xuMU4/uc1YNgZLFOeV8FGdhGrNk5SEgUyPxAEdj4LlMRDyhVAMVEa2M7TBSeVZAFPdqHgzSZJwPKgcLFLAooHDJo4EDCw4gAtBoJA5UFj4Ng5LOGLwVXZuoIlji/jeQHFk7+baHxrCjeUwB9+s88KndvlhcyBN5BSkYNQIVVb4pV+Npm7hhuKDs/uMP5KxT3WzSNNLIuuoDpMmuAVMruMSeDyQBi24DTr43LAY7ILA1QYaWkgfHzFthYYzg67SQsCbB8GhJUEGCtO9n0rSaCLxgJQjS/JSgMTg2eBDEHAJ+H350AsjYNYscrErgI2e/l+mdR967TCX/v6N0EhPECYCP0i+IAoYQOE8BogNhQMEMdrgAQWHaMAAGi5I5euoY9NAAAAAElFTkSuQmCC"></p>
-<p>and this is github's emoji <img width="20" height="20" align="absmiddle" src="https://assets-cdn.github.com/images/icons/emoji/octocat.png"></p>
+<p>and this is github's emoji <img width="20" height="20" align="absmiddle" src="https://github.githubassets.com/images/icons/emoji/octocat.png"></p>
diff --git a/test/functional/makehtml/testsuite.features.js b/test/functional/makehtml/testsuite.features.js
index 40f1252..cb0caa0 100644
--- a/test/functional/makehtml/testsuite.features.js
+++ b/test/functional/makehtml/testsuite.features.js
@@ -18,7 +18,10 @@ var bootstrap = require('./makehtml.bootstrap.js'),
     //literalMidWordAsterisksSuite = bootstrap.getTestSuite('test/functional/makehtml/cases/features/literalMidWordAsterisks/'),
     completeHTMLOutputSuite = bootstrap.getTestSuite('test/functional/makehtml/cases/features/completeHTMLOutput/'),
     metadataSuite = bootstrap.getTestSuite('test/functional/makehtml/cases/features/metadata/'),
-    splitAdjacentBlockquotesSuite = bootstrap.getTestSuite('test/functional/makehtml/cases/features/splitAdjacentBlockquotes/');
+    splitAdjacentBlockquotesSuite = bootstrap.getTestSuite('test/functional/makehtml/cases/features/splitAdjacentBlockquotes/'),
+    http = require('http'),
+    https = require('https'),
+    expect = require('chai').expect;
 
 describe('makeHtml() features testsuite', function () {
   'use strict';
@@ -190,7 +193,31 @@ describe('makeHtml() features testsuite', function () {
   /** test emojis support **/
   describe('emojis support', function () {
     var converter,
-        suite = emojisSuite;
+        suite = emojisSuite,
+        imgSrcRegexp = /<img[^>]+src=("https?:\/\/[^"]+"|'https?:\/\/[^']+')/g;
+
+    function testImageUrlExists (imgUrl) {
+      // Strip the quotes
+      imgUrl = imgUrl.substr(0, imgUrl.length - 1).substr(1);
+      return function (done) {
+        (imgUrl.startsWith('http://') ? http : https).get(imgUrl, function (res) {
+          expect(res.statusCode).to.equal(200);
+          // Make sure we get some data and that it's a png
+          expect(parseInt(res.headers['content-length'], 10)).to.be.above(0);
+          expect(res.headers['content-type']).to.equal('image/png');
+
+          // Discard the data (but fetch it)
+          res.on('data', function () {});
+
+          res.on('end', function () {
+            done();
+          });
+        }).on('error', function (e) {
+          throw e;
+        });
+      };
+    }
+
     for (var i = 0; i < suite.length; ++i) {
       if (suite[i].name === 'simplifiedautolinks') {
         converter = new showdown.Converter({emoji: true, simplifiedAutoLink: true});
@@ -199,6 +226,11 @@ describe('makeHtml() features testsuite', function () {
       }
 
       it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
+
+      var imgUrl = imgSrcRegexp.exec(suite[i].expected);
+      if (imgUrl) {
+        it('should use a working emoji URL', testImageUrlExists(imgUrl[1]));
+      }
     }
   });