From aff148828be988d2e084cebd63c32e502fe42d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 19 Apr 2017 15:52:50 +0200 Subject: [PATCH] Fix bug in website badge (specifying colours & test + subdirectories was improperly parsed). Allow specifying website name (left part of the badge). --- server.js | 26 +++++++++++++++++--------- try.html | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/server.js b/server.js index 5411be7ce4919..74e1740be0536 100644 --- a/server.js +++ b/server.js @@ -5833,21 +5833,22 @@ cache(function(data, match, sendBadge, request) { })); // Test if a webpage is online -camp.route(/^\/website(-(([^-]|--)*?)-(([^-]|--)*)(-(([^-]|--)+)-(([^-]|--)+))?)?\/([^/]+)\/(.+)\.(svg|png|gif|jpg|json)$/, +camp.route(/^\/website(-(([^-/]|--|\/\/)*?)-(([^-/]|--|\/\/)*)(-(([^-/]|--|\/\/)+)-(([^-/]|--|\/\/)+))?)?(-(([^-/]|--|\/\/)+))?\/([^/]+)\/(.+)\.(svg|png|gif|jpg|json)$/, cache(function(data, match, sendBadge, request) { - var onlineMessage = escapeFormat(match[2] != null ? match[2] : "online"); - var offlineMessage = escapeFormat(match[4] != null ? match[4] : "offline"); - var onlineColor = escapeFormat(match[7] != null ? match[7] : "brightgreen"); - var offlineColor = escapeFormat(match[9] != null ? match[9] : "red"); - var userProtocol = match[11]; - var userURI = match[12]; - var format = match[13]; + var onlineMessage = escapeFormatSlashes(match[2] != null ? match[2] : "online"); + var offlineMessage = escapeFormatSlashes(match[4] != null ? match[4] : "offline"); + var onlineColor = escapeFormatSlashes(match[7] != null ? match[7] : "brightgreen"); + var offlineColor = escapeFormatSlashes(match[9] != null ? match[9] : "red"); + var label = escapeFormatSlashes(match[12] != null ? match[12] : "website"); + var userProtocol = match[14]; + var userURI = match[15]; + var format = match[16]; var withProtocolURI = userProtocol + "://" + userURI; var options = { method: 'HEAD', uri: withProtocolURI, }; - var badgeData = getBadgeData('website', data); + var badgeData = getBadgeData(label, data); badgeData.colorscheme = undefined; request(options, function(err, res) { // We consider all HTTP status codes below 310 as success. @@ -6159,6 +6160,13 @@ function escapeFormat(t) { .replace(/__/g, '_').replace(/--/g, '-'); } +function escapeFormatSlashes(t) { + return escapeFormat(t) + // Double slash + .replace(/\/\//g, '/'); +} + + function sixHex(s) { return /^[0-9a-fA-F]{6}$/.test(s); } function getLabel(label, data) { diff --git a/try.html b/try.html index e9f5bf7c83ccc..5f5993a3f2d77 100644 --- a/try.html +++ b/try.html @@ -393,8 +393,8 @@

Downloads

https://img.shields.io/chrome-web-store/d/nimelepbpejjlbmoobocpfnjhihnpked.svg Website: - - https://img.shields.io/website-up-down-green-red/http/shields.io.svg + + https://img.shields.io/website-up-down-green-red-my--website/http/shields.io.svg CocoaPods: @@ -1201,10 +1201,16 @@

Like This?

+
Dashes -- @@ -1215,6 +1221,10 @@

Like This?

_ Underscore
Slashes // + → + / Slash
+
_ or Space     Space