Fix badge encoding for values including the _ underscore character

This commit is contained in:
Jozef Izso 2025-11-05 21:20:23 +01:00
parent 6079ce3d17
commit bed521d765
Failed to extract signature
2 changed files with 11 additions and 1 deletions

View file

@ -31,6 +31,16 @@ describe('getBadge', () => {
expect(badge).toBe('![Tests passed successfully](https://img.shields.io/badge/integration--api--tests-10%20passed-success)') expect(badge).toBe('![Tests passed successfully](https://img.shields.io/badge/integration--api--tests-10%20passed-success)')
}) })
it('handles badge title with multiple underscores', () => {
const options: ReportOptions = {
...DEFAULT_OPTIONS,
badgeTitle: 'my_integration_test'
}
const badge = getBadge(10, 0, 0, options)
// All underscores in the title should be encoded as __
expect(badge).toBe('![Tests passed successfully](https://img.shields.io/badge/my__integration__test-10%20passed-success)')
})
it('handles badge title with version format containing hyphen', () => { it('handles badge title with version format containing hyphen', () => {
const options: ReportOptions = { const options: ReportOptions = {
...DEFAULT_OPTIONS, ...DEFAULT_OPTIONS,

View file

@ -309,5 +309,5 @@ function getResultIcon(result: TestExecutionResult): string {
} }
function encodeImgShieldsURIComponent(component: string): string { function encodeImgShieldsURIComponent(component: string): string {
return encodeURIComponent(component).replace(/-/g, '--') return encodeURIComponent(component).replace(/-/g, '--').replace(/_/g, '__')
} }