Skip to content

Commit

Permalink
Redirect an old png badge with a number as a color; test on [static] (b…
Browse files Browse the repository at this point in the history
…adges#3412)

Fixes badges#3260

Problem happens when a value of a color in an old PNG static badge is a number: http://localhost:8080/my-label/my-message.png?color=1. In this case `color` in `queryParams` is a number. 
https://github.com/badges/shields/blob/0a0b5b3f031178851c9d295b9967d81ede052723/core/server/server.js#L203-L212

Surprisingly service test listed below is passing currently on master - value `1` is represented in `queryParams` as a String (only in test). 
`services/static-badge/static-badge.tester.js`
```js
t.create('Old static badge with a number as a color')
  .get('/foo/bar.png?color=1', { followRedirect: false })
  .expectStatus(301)
  .expectHeader('Location', '/badge/foo-bar-1.png')
```

Moreover I added some code + description allowing to debug server.
  • Loading branch information
platan authored and paulmelnikow committed May 8, 2019
1 parent 7afb26e commit 2836014
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Node: Nodemon",
"processId": "${command:PickProcess}",
"restart": true,
"protocol": "inspector"
}
]
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ To debug a badge from the command line, run `npm run badge -- /npm/v/nock.svg`.
It also works with full URLs like
`npm run badge -- https://img.shields.io/npm/v/nock.svg`.

Use `npm run debug:server` to start server in debug mode.
[This recipe][nodemon debug] shows how to debug Node.js application in [VS Code][].

Shields has experimental support for [Gitpod Beta][gitpod], a pre-configured development
environment that runs in your browser. To use Gitpod, click the button below and
sign in with GitHub. Gitpod also offers a browser add-on, though it is not required.
Expand All @@ -137,6 +140,8 @@ Daily tests, including a full run of the service tests and overall code coverage
[sentry configuration]: doc/self-hosting.md#sentry
[daily-tests]: https://github.com/badges/daily-tests
[nodemon]: https://nodemon.io/
[nodemon debug]: https://github.com/Microsoft/vscode-recipes/tree/master/nodemon
[vs code]: https://code.visualstudio.com/

## Hosting your own server

Expand Down
3 changes: 2 additions & 1 deletion core/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ module.exports = class Server {
const redirectUrl = staticBadgeUrl({
label,
message,
color,
// Fixes https://github.com/badges/shields/issues/3260
color: color ? color.toString() : undefined,
format: 'png',
})

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"now-start": "npm run start:server:prod",
"start:server:e2e-on-build": "node server 8080",
"start:server": "cross-env NODE_CONFIG_ENV=development nodemon server 8080",
"debug:server": "cross-env NODE_CONFIG_ENV=development nodemon --inspect server.js 8080",
"prestart": "run-s --silent depcheck defs features",
"start": "concurrently --names server,frontend \"npm run start:server\" \"cross-env GATSBY_BASE_URL=http://localhost:8080 gatsby develop --port 3000\"",
"e2e": "start-server-and-test start http://localhost:3000 test:e2e",
Expand Down
5 changes: 5 additions & 0 deletions services/static-badge/static-badge.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ t.create('Old static badge')
.get('/foo/bar.png?color=blue', { followRedirect: false })
.expectStatus(301)
.expectHeader('Location', '/badge/foo-bar-blue.png')

t.create('Old static badge without a color')
.get('/foo/bar.png', { followRedirect: false })
.expectStatus(301)
.expectHeader('Location', '/badge/foo-bar-lightgray.png')

0 comments on commit 2836014

Please sign in to comment.