Skip to content

Commit

Permalink
Merge pull request anuraghazra#178 from anuraghazra/fix-unicode
Browse files Browse the repository at this point in the history
fix: weird unicode char
  • Loading branch information
anuraghazra authored Jul 24, 2020
2 parents f9b14c9 + 2812ce0 commit e32ab3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/renderStatsCard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const { kFormatter, getCardColors, FlexLayout } = require("../src/utils");
const {
kFormatter,
getCardColors,
FlexLayout,
encodeHTML,
} = require("../src/utils");
const getStyles = require("./getStyles");
const icons = require("./icons");

Expand Down Expand Up @@ -128,7 +133,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
const apostrophe = ["x", "s"].includes(name.slice(-1)) ? "" : "s";
const title = hide_title
? ""
: `<text x="25" y="35" class="header">${name}'${apostrophe} GitHub Stats</text>`;
: `<text x="25" y="35" class="header">${encodeHTML(name)}'${apostrophe} GitHub Stats</text>`;

const border = `
<rect
Expand Down
8 changes: 5 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ const renderError = (message) => {

// https://stackoverflow.com/a/48073476/10629172
function encodeHTML(str) {
return str.replace(/[\u00A0-\u9999<>&](?!#)/gim, function (i) {
return "&#" + i.charCodeAt(0) + ";";
});
return str
.replace(/[\u00A0-\u9999<>&](?!#)/gim, (i) => {
return "&#" + i.charCodeAt(0) + ";";
})
.replace(/\u0008/gim, "");
}

function kFormatter(num) {
Expand Down

0 comments on commit e32ab3f

Please sign in to comment.