Fixed escapes single '_' of badge urls; affects [static website] (#5979)

Fixed escapes inline single '_' of badge urls

Co-authored-by: chris48s <chris48s@users.noreply.github.com>
This commit is contained in:
SeaHOH
2020-12-26 02:20:42 +08:00
committed by GitHub
parent d968c8d277
commit 8d94869bf8
2 changed files with 23 additions and 5 deletions

View File

@@ -5,11 +5,8 @@
function escapeFormat(t) {
return (
t
// Inline single underscore.
.replace(/([^_])_([^_])/g, '$1 $2')
// Leading or trailing underscore.
.replace(/([^_])_$/, '$1 ')
.replace(/^_([^_])/, ' $1')
// Single underscore.
.replace(/(^|[^_])((?:__)*)_(?!_)/g, '$1$2 ')
// Double underscore and double dash.
.replace(/__/g, '_')
.replace(/--/g, '-')

View File

@@ -0,0 +1,21 @@
'use strict'
const { test, given } = require('sazerac')
const { escapeFormat } = require('./path-helpers')
describe('Badge URL helper functions', function () {
test(escapeFormat, () => {
given('_single leading underscore').expect(' single leading underscore')
given('single trailing underscore_').expect('single trailing underscore ')
given('__double leading underscores').expect('_double leading underscores')
given('double trailing underscores__').expect(
'double trailing underscores_'
)
given('treble___underscores').expect('treble_ underscores')
given('fourfold____underscores').expect('fourfold__underscores')
given('double--dashes').expect('double-dashes')
given('treble---dashes').expect('treble--dashes')
given('fourfold----dashes').expect('fourfold--dashes')
given('once_in_a_blue--moon').expect('once in a blue-moon')
})
})