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:
@@ -5,11 +5,8 @@
|
|||||||
function escapeFormat(t) {
|
function escapeFormat(t) {
|
||||||
return (
|
return (
|
||||||
t
|
t
|
||||||
// Inline single underscore.
|
// Single underscore.
|
||||||
.replace(/([^_])_([^_])/g, '$1 $2')
|
.replace(/(^|[^_])((?:__)*)_(?!_)/g, '$1$2 ')
|
||||||
// Leading or trailing underscore.
|
|
||||||
.replace(/([^_])_$/, '$1 ')
|
|
||||||
.replace(/^_([^_])/, ' $1')
|
|
||||||
// Double underscore and double dash.
|
// Double underscore and double dash.
|
||||||
.replace(/__/g, '_')
|
.replace(/__/g, '_')
|
||||||
.replace(/--/g, '-')
|
.replace(/--/g, '-')
|
||||||
|
|||||||
21
core/badge-urls/path-helpers.spec.js
Normal file
21
core/badge-urls/path-helpers.spec.js
Normal 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')
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user