Merge pull request #178 from anuraghazra/fix-unicode

fix: weird unicode char
This commit is contained in:
Anurag Hazra 2020-07-24 23:46:38 +05:30 committed by GitHub
commit e32ab3f973
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -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");
@ -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

View File

@ -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) {