Don't crash when logo passed as integer (#1319)
This commit is contained in:
committed by
Paul Melnikow
parent
e91c9fc7ab
commit
02683afd04
@@ -20,7 +20,11 @@ function isDataUri(s) {
|
||||
function prependPrefix(s, prefix) {
|
||||
if (s === undefined) {
|
||||
return undefined;
|
||||
} else if (s.startsWith(prefix)) {
|
||||
}
|
||||
|
||||
s = '' + s;
|
||||
|
||||
if (s.startsWith(prefix)) {
|
||||
return s;
|
||||
} else {
|
||||
return prefix + s;
|
||||
@@ -59,8 +63,10 @@ function makeLabel(defaultLabel, overrides) {
|
||||
}
|
||||
|
||||
function makeLogo(defaultNamedLogo, overrides) {
|
||||
const maybeDataUri = prependPrefix(overrides.logo, 'data:');
|
||||
const maybeNamedLogo = overrides.logo === undefined ? defaultNamedLogo : overrides.logo;
|
||||
const logo = 'logo' in overrides ? '' + overrides.logo : undefined;
|
||||
|
||||
const maybeDataUri = prependPrefix(logo, 'data:');
|
||||
const maybeNamedLogo = logo === undefined ? defaultNamedLogo : logo;
|
||||
|
||||
if (isDataUri(maybeDataUri)) {
|
||||
return maybeDataUri;
|
||||
|
||||
@@ -43,6 +43,19 @@ describe('The server', function () {
|
||||
});
|
||||
});
|
||||
|
||||
// https://github.com/badges/shields/pull/1319
|
||||
it('should not crash with a numeric logo', function () {
|
||||
return fetch(`${baseUri}/:fruit-apple-green.svg?logo=1`)
|
||||
.then(res => {
|
||||
assert.ok(res.ok);
|
||||
return res.buffer();
|
||||
}).then(text => {
|
||||
assert.ok(isSvg(text));
|
||||
assert(text.includes('fruit'), 'fruit');
|
||||
assert(text.includes('apple'), 'apple');
|
||||
});
|
||||
});
|
||||
|
||||
context('with svg2img error', function () {
|
||||
const expectedError = fs.readFileSync(path.resolve(__dirname, 'public', '500.html'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user